refactor: Centralize error and notification handling using a dedicated _errorService across various components.
This commit is contained in:
@@ -876,17 +876,16 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
|
||||
if (!emailRegex.hasMatch(email)) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Email invalide')));
|
||||
_errorService.showError(message: 'Email invalide');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_participants.contains(email)) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Ce participant est déjà ajouté')),
|
||||
_errorService.showSnackbar(
|
||||
message: 'Ce participant est déjà ajouté',
|
||||
isError: true,
|
||||
);
|
||||
}
|
||||
return;
|
||||
@@ -962,11 +961,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Groupe et compte mis à jour avec succès !'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
_errorService.showSnackbar(
|
||||
message: 'Groupe et compte mis à jour avec succès !',
|
||||
isError: false,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -1048,11 +1045,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Voyage, groupe et compte créés avec succès !'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
_errorService.showSnackbar(
|
||||
message: 'Voyage, groupe et compte créés avec succès !',
|
||||
isError: false,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -1066,9 +1061,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||
);
|
||||
_errorService.showError(message: 'Erreur: $e');
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
@@ -1083,8 +1076,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
|
||||
if (_startDate == null || _endDate == null) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Veuillez sélectionner les dates')),
|
||||
_errorService.showSnackbar(
|
||||
message: 'Veuillez sélectionner les dates',
|
||||
isError: true,
|
||||
);
|
||||
}
|
||||
return;
|
||||
@@ -1129,14 +1123,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
// Continuer sans coordonnées en cas d'erreur
|
||||
tripWithCoordinates = trip;
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
_errorService.showSnackbar(
|
||||
message:
|
||||
'Voyage créé sans géolocalisation (pas d\'impact sur les fonctionnalités)',
|
||||
),
|
||||
backgroundColor: Colors.orange,
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
isError: true, // Warning displayed as error for now
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1167,9 +1157,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||
);
|
||||
_errorService.showError(message: 'Erreur: $e');
|
||||
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -1200,11 +1188,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
});
|
||||
} else {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Utilisateur non trouvé: $email'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
_errorService.showSnackbar(
|
||||
message: 'Utilisateur non trouvé: $email',
|
||||
isError: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -547,11 +547,9 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||
}
|
||||
|
||||
void _showComingSoon(String feature) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('$feature - Fonctionnalité à venir'),
|
||||
backgroundColor: Colors.blue,
|
||||
),
|
||||
_errorService.showSnackbar(
|
||||
message: '$feature - Fonctionnalité à venir',
|
||||
isError: false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -868,11 +866,8 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||
_addParticipantByEmail(emailController.text);
|
||||
Navigator.pop(context);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Veuillez entrer un email valide'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
_errorService.showError(
|
||||
message: 'Veuillez entrer un email valide',
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -940,11 +935,9 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||
TripUpdateRequested(trip: updatedTrip),
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('${user.prenom} a été ajouté au voyage'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
_errorService.showSnackbar(
|
||||
message: '${user.prenom} a été ajouté au voyage',
|
||||
isError: false,
|
||||
);
|
||||
|
||||
// Rafraîchir la page
|
||||
|
||||
Reference in New Issue
Block a user