feat: integrate ErrorService for consistent error display and standardize bloc error messages.

This commit is contained in:
Van Leemput Dayron
2025-12-02 13:59:40 +01:00
parent 1e70b9e09f
commit 6757cb013a
24 changed files with 927 additions and 608 deletions

View File

@@ -11,6 +11,7 @@ import '../blocs/user/user_bloc.dart';
import '../blocs/user/user_event.dart';
import '../blocs/auth/auth_bloc.dart';
import '../blocs/auth/auth_event.dart';
import '../services/error_service.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@@ -119,12 +120,7 @@ class _HomePageState extends State<HomePage> {
);
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Erreur lors de la déconnexion: $e'),
backgroundColor: Colors.red,
),
);
ErrorService().showError(message: 'Erreur lors de la déconnexion: $e');
}
}
}
@@ -132,38 +128,51 @@ class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(titles[_currentIndex]),
),
appBar: AppBar(title: Text(titles[_currentIndex])),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
decoration: BoxDecoration(
color: Theme.of(context).brightness == Brightness.dark
? Colors.black
: Colors.white,
color: Theme.of(context).brightness == Brightness.dark
? Colors.black
: Colors.white,
),
child: Text(
"Travel Mate",
style: TextStyle(
color: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black,
color: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black,
fontSize: 24,
),
),
),
_buildDrawerItem(icon: Icons.home, title: "Mes voyages", index: 0),
_buildDrawerItem(icon: Icons.settings, title: "Paramètres", index: 1),
_buildDrawerItem(
icon: Icons.settings,
title: "Paramètres",
index: 1,
),
_buildDrawerItem(icon: Icons.map, title: "Carte", index: 2),
_buildDrawerItem(icon: Icons.group, title: "Chat de groupe", index: 3),
_buildDrawerItem(icon: Icons.account_balance_wallet, title: "Comptes", index: 4),
_buildDrawerItem(
icon: Icons.group,
title: "Chat de groupe",
index: 3,
),
_buildDrawerItem(
icon: Icons.account_balance_wallet,
title: "Comptes",
index: 4,
),
const Divider(),
ListTile(
leading: const Icon(Icons.logout, color: Colors.red),
title: const Text("Déconnexion", style: TextStyle(color: Colors.red)),
title: const Text(
"Déconnexion",
style: TextStyle(color: Colors.red),
),
onTap: _handleLogout, // Utiliser la nouvelle méthode
),
],
@@ -191,7 +200,9 @@ class _HomePageState extends State<HomePage> {
leading: Icon(icon),
title: Text(title),
selected: _currentIndex == index,
selectedTileColor: Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
selectedTileColor: Theme.of(
context,
).colorScheme.primary.withValues(alpha: 0.1),
onTap: () => _onNavigationTap(index),
);
}
@@ -201,4 +212,4 @@ class _HomePageState extends State<HomePage> {
_pageCache.clear();
super.dispose();
}
}
}

View File

@@ -4,6 +4,7 @@ import '../blocs/auth/auth_bloc.dart';
import '../blocs/auth/auth_event.dart';
import '../blocs/auth/auth_state.dart';
import 'package:sign_in_button/sign_in_button.dart';
import '../services/error_service.dart';
/// Login page widget for user authentication.
///
@@ -89,12 +90,7 @@ class _LoginPageState extends State<LoginPage> {
if (state is AuthAuthenticated) {
Navigator.pushReplacementNamed(context, '/home');
} else if (state is AuthError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
backgroundColor: Colors.red,
),
);
ErrorService().showError(message: state.message);
}
},
builder: (context, state) {

View File

@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import '../blocs/auth/auth_bloc.dart';
import '../blocs/auth/auth_event.dart';
import '../blocs/auth/auth_state.dart';
import '../services/error_service.dart';
class ForgotPasswordPage extends StatefulWidget {
const ForgotPasswordPage({super.key});
@@ -56,20 +57,13 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
body: BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
if (state is AuthPasswordResetSent) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Email de réinitialisation envoyé !'),
backgroundColor: Colors.green,
),
ErrorService().showSnackbar(
message: 'Email de réinitialisation envoyé !',
isError: false,
);
Navigator.pop(context);
} else if (state is AuthError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
backgroundColor: Colors.red,
),
);
ErrorService().showError(message: state.message);
}
},
child: SafeArea(

View File

@@ -117,9 +117,7 @@ class _SignUpPageState extends State<SignUpPage> {
);
Navigator.pushReplacementNamed(context, '/home');
} else if (state is AuthError) {
_errorService.showError(
message: 'Erreur lors de la création du compte',
);
_errorService.showError(message: state.message);
}
},
builder: (context, state) {