Skip to content

Commit

Permalink
added routes to registration widget
Browse files Browse the repository at this point in the history
  • Loading branch information
SMSourov committed Sep 25, 2023
1 parent 5776d00 commit daddc5f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/constants/routes.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const loginRoute = "/login/";
const registerRoute = "/register/";
const notesRoute = "/notes/";
const notesRoute = "/notes/";
const verifyEmailRoute = "/verify-email/";
6 changes: 5 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:js';

import 'package:cleanifi/constants/routes.dart';
import 'package:cleanifi/firebase_options.dart';
import 'package:cleanifi/views/login_view.dart';
Expand All @@ -23,6 +25,7 @@ void main() {
loginRoute: (context) => const LoginView(),
registerRoute: (context) => const RegisterView(),
notesRoute: (context) => const NotesView(),
verifyEmailRoute: (context) => const VerifyEmailView(),
},
),
);
Expand Down Expand Up @@ -86,7 +89,8 @@ class _NotesViewState extends State<NotesView> {
final shouldLogOut = await showLogOutDialog(context);
if (shouldLogOut) {
await FirebaseAuth.instance.signOut();
Navigator.of(context).pushNamedAndRemoveUntil(loginRoute, (_) => false);
Navigator.of(context)
.pushNamedAndRemoveUntil(loginRoute, (_) => false);
}
}
},
Expand Down
12 changes: 6 additions & 6 deletions lib/views/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ class _LoginViewState extends State<LoginView> {
"Error: ${e.code}",
);
}
} catch (e) {
await showErrorDialog(
context,
e.toString(),
);
}

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

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

47 changes: 31 additions & 16 deletions lib/views/register_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 RegisterView extends StatefulWidget {
const RegisterView({super.key});
Expand Down Expand Up @@ -33,7 +33,9 @@ class _RegisterViewState extends State<RegisterView> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Register"),),
appBar: AppBar(
title: const Text("Register"),
),
body: Column(
children: [
TextField(
Expand All @@ -60,30 +62,43 @@ class _RegisterViewState extends State<RegisterView> {
final email = _email.text;
final password = _password.text;
try {
final userCredential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email, password: password);
devtools.log(userCredential.toString());
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: email,
password: password,
);
Navigator.of(context).pushNamed(verifyEmailRoute);
} on FirebaseAuthException catch (e) {
if (e.code == "email-already-in-use") {
devtools.log("Unable to register.");
devtools.log("The given email is already registered.");
await showErrorDialog(
context,
"An account is already registered with this email.",
);
} else if (e.code == "weak-password") {
devtools.log("Password is not accepted");
devtools.log("Use a stronger password.");
await showErrorDialog(
context,
"Week password",
);
} else if (e.code == "invalid-email") {
devtools.log("The given email is not an email.");
await showErrorDialog(
context,
"Enter a valid email address.",
);
} else {
devtools.log(e.code);
await showErrorDialog(
context,
e.toString(),
);
}
}
},
child: const Text("Register"),
),
TextButton(onPressed: () {
Navigator.of(context)
.pushNamedAndRemoveUntil(loginRoute, (route) => false);
}, child: const Text("Already registered?\n Login here!"))
TextButton(
onPressed: () {
Navigator.of(context)
.pushNamedAndRemoveUntil(loginRoute, (route) => false);
},
child: const Text("Already registered?\n Login here!"))
],
),
);
Expand Down

0 comments on commit daddc5f

Please sign in to comment.