From c0656918732f8324b050f76343af287498aa2f9a Mon Sep 17 00:00:00 2001 From: Peter Kyeyune Date: Wed, 19 Feb 2025 16:32:24 +0300 Subject: [PATCH] refactor logout process to improve error handling and navigation flow --- .../app/dashboard/pages/dashboard_page.dart | 34 +++++----- .../src/app/learn/pages/lesson_finished.dart | 20 +++--- .../pages/widgets/settings_widget.dart | 62 ++++++++++--------- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart b/mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart index 6d88eaa80b..889c726397 100644 --- a/mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart +++ b/mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart @@ -106,24 +106,24 @@ class _DashboardPageState extends State { ), SizedBox(width: 8), GestureDetector( - onTap: () { - final authState = context.read().state; - if (authState is GuestUser) { + // onTap: () { + // final authState = context.read().state; + // if (authState is GuestUser) { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => GuestProfilePage(), - ), - ); - } else { - // Navigate to the regular profile page - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => ProfilePage(), - ), - ); - } - }, + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (context) => GuestProfilePage(), + // ), + // ); + // } else { + // // Navigate to the regular profile page + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (context) => ProfilePage(), + // ), + // ); + // } + // }, child: BlocBuilder( builder: (context, authState) { if (authState is GuestUser) { diff --git a/mobile-v3/lib/src/app/learn/pages/lesson_finished.dart b/mobile-v3/lib/src/app/learn/pages/lesson_finished.dart index 8ef0b579c4..88674000d3 100644 --- a/mobile-v3/lib/src/app/learn/pages/lesson_finished.dart +++ b/mobile-v3/lib/src/app/learn/pages/lesson_finished.dart @@ -14,19 +14,19 @@ class LessonFinishedWidget extends StatelessWidget { Text("👋🏼 Great Job !", style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700)), Text( - "You can invite your friends to learn a thing about Air Pollution", + "You can now teach your friends to learn a thing about Air Pollution", textAlign: TextAlign.center, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)), SizedBox(height: 64), - SmallRoundedButton( - label: "Share", - imagePath: "assets/images/shared/share_icon.svg", - ), - SizedBox(height: 16), - SmallRoundedButton( - label: "Rate the App", - imagePath: "assets/images/shared/bookmark_icon.svg", - ), + // SmallRoundedButton( + // label: "Share", + // imagePath: "assets/images/shared/share_icon.svg", + // ), + // SizedBox(height: 16), + // SmallRoundedButton( + // label: "Rate the App", + // imagePath: "assets/images/shared/bookmark_icon.svg", + // ), ], ), ); diff --git a/mobile-v3/lib/src/app/profile/pages/widgets/settings_widget.dart b/mobile-v3/lib/src/app/profile/pages/widgets/settings_widget.dart index 3e1c5fea9f..2410a330d3 100644 --- a/mobile-v3/lib/src/app/profile/pages/widgets/settings_widget.dart +++ b/mobile-v3/lib/src/app/profile/pages/widgets/settings_widget.dart @@ -52,41 +52,45 @@ class _SettingsWidgetState extends State { } Future _handleLogout(BuildContext dialogContext) async { - Navigator.pop(dialogContext); + Navigator.pop(dialogContext); // Close confirmation dialog - showDialog( - context: context, - barrierDismissible: false, - builder: (_) => const Center(child: CircularProgressIndicator()), - ); + showDialog( + context: context, + barrierDismissible: false, + builder: (_) => const Center(child: CircularProgressIndicator()), + ); + + try { + context.read().add(LogoutUser()); + + await for (final state in context.read().stream) { + if (state is GuestUser) { + Navigator.pop(context); - try { - context.read().add(LogoutUser()); + await Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute(builder: (_) => WelcomeScreen()), + (route) => false, + ); + break; + } else if (state is AuthLoadingError) { + Navigator.pop(context); - await for (final state in context.read().stream) { - if (state is GuestUser) { - Navigator.pop(context); - await Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute(builder: (_) => WelcomeScreen()), - (route) => false, - ); - break; - } else if (state is AuthLoadingError) { - Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(state.message)), - ); - break; - } + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(state.message)), + ); + break; } - } catch (e) { - Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('An unexpected error occurred')), - ); } + } catch (e) { + Navigator.pop(context); + + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('An unexpected error occurred')), + ); } +} + void _showDeleteAccountDialog() { final TextEditingController passwordController = TextEditingController();