From a2c2b9570dbc4de98ad50ce0bc6d7e690ed9a978 Mon Sep 17 00:00:00 2001 From: Evan Ferrao Date: Mon, 8 Jul 2024 05:08:33 +0530 Subject: [PATCH] mynotes: add error popup in login page --- lib/utilities/show_error_dialog.dart | 24 ++++++++++++++++++++++++ lib/views/login_view.dart | 27 ++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 lib/utilities/show_error_dialog.dart diff --git a/lib/utilities/show_error_dialog.dart b/lib/utilities/show_error_dialog.dart new file mode 100644 index 0000000..54c2f72 --- /dev/null +++ b/lib/utilities/show_error_dialog.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; + +Future showErrorDialog( + BuildContext context, + String text, +) { + return showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('An error occurred'), + content: Text(text), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ) + ], + ); + }, + ); +} diff --git a/lib/views/login_view.dart b/lib/views/login_view.dart index af8c089..b6b1ddf 100644 --- a/lib/views/login_view.dart +++ b/lib/views/login_view.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:mynotes/constants/routes.dart'; import 'package:mynotes/firebase_options.dart'; import 'dart:developer' as devtools show log; +import 'package:mynotes/utilities/show_error_dialog.dart'; class LoginView extends StatefulWidget { const LoginView({super.key}); @@ -73,15 +74,31 @@ class _LoginViewState extends State { ); } on FirebaseAuthException catch (e) { if (e.code == 'user-not-found') { - devtools.log('No user found for that email.'); + await showErrorDialog( + context, + 'No user found for that email.', + ); } else if (e.code == 'wrong-password') { - devtools.log('Wrong password provided for that user.'); + await showErrorDialog( + context, + 'Wrong password provided for that user.', + ); } else if (e.code == 'invalid-credential') { - devtools.log('Invalid credential provided.'); + await showErrorDialog( + context, + 'Invalid credential provided.', + ); + } else { + await showErrorDialog( + context, + e.toString(), + ); } } catch (e) { - devtools.log(e.toString()); - devtools.log(e.runtimeType.toString()); + await showErrorDialog( + context, + e.toString(), + ); } }, child: const Text('Login', style: TextStyle(color: Colors.blue)),