Skip to content

Commit

Permalink
refactor logout process to improve error handling and navigation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Mozart299 committed Feb 19, 2025
1 parent 5d081e6 commit c065691
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
34 changes: 17 additions & 17 deletions mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,24 @@ class _DashboardPageState extends State<DashboardPage> {
),
SizedBox(width: 8),
GestureDetector(
onTap: () {
final authState = context.read<AuthBloc>().state;
if (authState is GuestUser) {
// onTap: () {
// final authState = context.read<AuthBloc>().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<AuthBloc, AuthState>(
builder: (context, authState) {
if (authState is GuestUser) {
Expand Down
20 changes: 10 additions & 10 deletions mobile-v3/lib/src/app/learn/pages/lesson_finished.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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",
// ),
],
),
);
Expand Down
62 changes: 33 additions & 29 deletions mobile-v3/lib/src/app/profile/pages/widgets/settings_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,41 +52,45 @@ class _SettingsWidgetState extends State<SettingsWidget> {
}

Future<void> _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<AuthBloc>().add(LogoutUser());

await for (final state in context.read<AuthBloc>().stream) {
if (state is GuestUser) {
Navigator.pop(context);

try {
context.read<AuthBloc>().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<AuthBloc>().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();
Expand Down

0 comments on commit c065691

Please sign in to comment.