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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user