refactor: Centralize error and notification handling using a dedicated _errorService across various components.

This commit is contained in:
Van Leemput Dayron
2025-12-03 14:50:03 +01:00
parent 6757cb013a
commit f3ae91ccf9
10 changed files with 91 additions and 249 deletions

View File

@@ -63,6 +63,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:image_picker/image_picker.dart';
import 'package:intl/intl.dart';
import 'package:travel_mate/models/expense_split.dart';
import '../../services/error_service.dart';
import '../../blocs/expense/expense_bloc.dart';
import '../../blocs/expense/expense_event.dart';
import '../../blocs/expense/expense_state.dart';
@@ -191,11 +192,8 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
if (fileSize > 5 * 1024 * 1024) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('L\'image ne doit pas dépasser 5 Mo'),
backgroundColor: Colors.red,
),
ErrorService().showError(
message: 'L\'image ne doit pas dépasser 5 Mo',
);
}
return;
@@ -247,11 +245,8 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
}).toList();
if (selectedSplits.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Veuillez sélectionner au moins un participant'),
backgroundColor: Colors.red,
),
ErrorService().showError(
message: 'Veuillez sélectionner au moins un participant',
);
return;
}
@@ -299,22 +294,16 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
if (mounted) {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
widget.expenseToEdit == null
? 'Dépense ajoutée'
: 'Dépense modifiée',
),
backgroundColor: Colors.green,
),
ErrorService().showSnackbar(
message: widget.expenseToEdit == null
? 'Dépense ajoutée'
: 'Dépense modifiée',
isError: false,
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
);
ErrorService().showError(message: 'Erreur: $e');
}
} finally {
if (mounted) {