mirror of https://github.com/evanferrao/mynotes
mynotes: add error popup in login page
This commit is contained in:
parent
c6944a1f7b
commit
a2c2b9570d
|
|
@ -0,0 +1,24 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
Future<void> 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'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:mynotes/constants/routes.dart';
|
import 'package:mynotes/constants/routes.dart';
|
||||||
import 'package:mynotes/firebase_options.dart';
|
import 'package:mynotes/firebase_options.dart';
|
||||||
import 'dart:developer' as devtools show log;
|
import 'dart:developer' as devtools show log;
|
||||||
|
import 'package:mynotes/utilities/show_error_dialog.dart';
|
||||||
|
|
||||||
class LoginView extends StatefulWidget {
|
class LoginView extends StatefulWidget {
|
||||||
const LoginView({super.key});
|
const LoginView({super.key});
|
||||||
|
|
@ -73,15 +74,31 @@ class _LoginViewState extends State<LoginView> {
|
||||||
);
|
);
|
||||||
} on FirebaseAuthException catch (e) {
|
} on FirebaseAuthException catch (e) {
|
||||||
if (e.code == 'user-not-found') {
|
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') {
|
} 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') {
|
} 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) {
|
} catch (e) {
|
||||||
devtools.log(e.toString());
|
await showErrorDialog(
|
||||||
devtools.log(e.runtimeType.toString());
|
context,
|
||||||
|
e.toString(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Text('Login', style: TextStyle(color: Colors.blue)),
|
child: const Text('Login', style: TextStyle(color: Colors.blue)),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue