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

@@ -502,11 +502,9 @@ class ProfileContent extends StatelessWidget {
);
Navigator.of(dialogContext).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Profil mis à jour !'),
backgroundColor: Colors.green,
),
_errorService.showSnackbar(
message: 'Profil mis à jour !',
isError: false,
);
}
},
@@ -668,11 +666,9 @@ class ProfileContent extends StatelessWidget {
if (context.mounted) {
LoggerService.info('DEBUG: Affichage du succès');
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Photo de profil mise à jour !'),
backgroundColor: Colors.green,
),
_errorService.showSnackbar(
message: 'Photo de profil mise à jour !',
isError: false,
);
}
} catch (e, stackTrace) {
@@ -736,22 +732,16 @@ class ProfileContent extends StatelessWidget {
if (currentPasswordController.text.isEmpty ||
newPasswordController.text.isEmpty ||
confirmPasswordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Tous les champs sont requis'),
backgroundColor: Colors.red,
),
_errorService.showError(
message: 'Tous les champs sont requis',
);
return;
}
if (newPasswordController.text !=
confirmPasswordController.text) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Les mots de passe ne correspondent pas'),
backgroundColor: Colors.red,
),
_errorService.showError(
message: 'Les mots de passe ne correspondent pas',
);
return;
}
@@ -765,11 +755,9 @@ class ProfileContent extends StatelessWidget {
if (context.mounted) {
Navigator.of(dialogContext).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Mot de passe changé !'),
backgroundColor: Colors.green,
),
_errorService.showSnackbar(
message: 'Mot de passe changé !',
isError: false,
);
}
} catch (e) {
@@ -823,11 +811,8 @@ class ProfileContent extends StatelessWidget {
TextButton(
onPressed: () async {
if (confirmationController.text != 'CONFIRMER') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Veuillez écrire CONFIRMER pour valider'),
backgroundColor: Colors.red,
),
_errorService.showError(
message: 'Veuillez écrire CONFIRMER pour valider',
);
return;
}
@@ -848,14 +833,10 @@ class ProfileContent extends StatelessWidget {
if (e.code == 'requires-recent-login') {
if (context.mounted) {
Navigator.of(dialogContext).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
_errorService.showSnackbar(
message:
'Par sécurité, veuillez vous reconnecter avant de supprimer votre compte',
),
backgroundColor: Colors.orange,
duration: Duration(seconds: 4),
),
isError: true, // It's a warning/error
);
}
} else {