refactor: Centralize error and notification handling using a dedicated _errorService across various components.
This commit is contained in:
@@ -11,6 +11,7 @@ import '../../blocs/trip/trip_bloc.dart';
|
||||
import '../../blocs/trip/trip_state.dart';
|
||||
import '../../blocs/trip/trip_event.dart';
|
||||
import '../../models/trip.dart';
|
||||
import '../../services/error_service.dart';
|
||||
|
||||
/// Home content widget for the main application dashboard.
|
||||
///
|
||||
@@ -79,26 +80,16 @@ class _HomeContentState extends State<HomeContent>
|
||||
return BlocConsumer<TripBloc, TripState>(
|
||||
listener: (context, tripState) {
|
||||
if (tripState is TripOperationSuccess) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(tripState.message),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
ErrorService().showSnackbar(
|
||||
message: tripState.message,
|
||||
isError: false,
|
||||
);
|
||||
} else if (tripState is TripError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(tripState.message),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
ErrorService().showError(message: tripState.message);
|
||||
} else if (tripState is TripCreated) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Voyage en cours de création...'),
|
||||
backgroundColor: Colors.blue,
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
ErrorService().showSnackbar(
|
||||
message: 'Voyage en cours de création...',
|
||||
isError: false,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user