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)),