Skip to content

Commit

Permalink
Showing pop up for all error in login widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
SMSourov committed Sep 24, 2023
1 parent 5886c65 commit 5776d00
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
24 changes: 24 additions & 0 deletions lib/utilities/show_error_dialog.dart
Original file line number Diff line number Diff line change
@@ -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("Something went wrong"),
content: Text(text),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("OK"),
)
],
);
},
);
}
39 changes: 29 additions & 10 deletions lib/views/login_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:cleanifi/constants/routes.dart';
import 'package:cleanifi/utilities/show_error_dialog.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'dart:developer' as devtools show log;

class LoginView extends StatefulWidget {
const LoginView({super.key});
Expand Down Expand Up @@ -59,12 +59,12 @@ class _LoginViewState extends State<LoginView> {
),
TextButton(
onPressed: () async {
final email = _email.text;
final password = _password.text;
final email = _email.text;
final password = _password.text;

try {
// final userCredential =
await FirebaseAuth.instance.signInWithEmailAndPassword(
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: email,
password: password,
);
Expand All @@ -75,14 +75,32 @@ class _LoginViewState extends State<LoginView> {
);
} on FirebaseAuthException catch (e) {
if (e.code == "user-not-found") {
devtools.log("The user was not found. That's all we know.");
await showErrorDialog(
context,
"The user was not found.\nThat's all we know.",
);
// devtools.log("The user was not found. That's all we know.");
} else if (e.code == "wrong-password") {
devtools.log("Incorrect password.");
// devtools.log("Incorrect password.");
await showErrorDialog(
context,
"Incorrect password",
);
} else {
devtools.log("Something else happend.");
devtools.log(e.code);
// devtools.log("Something else happend.");
// devtools.log(e.code);
await showErrorDialog(
context,
"Error: ${e.code}",
);
}
} //catch (e) {
}

catch (e) {
await showErrorDialog(context, e.toString(),);
}

//catch (e) {
// print("Something bad happend.");
// print(e);
// print(e.runtimeType);
Expand All @@ -103,3 +121,4 @@ class _LoginViewState extends State<LoginView> {
);
}
}

0 comments on commit 5776d00

Please sign in to comment.