diff --git a/analysis_options.yaml b/analysis_options.yaml index 0d29021..fc8e8a3 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,6 +7,9 @@ # The following line activates a set of recommended lints for Flutter apps, # packages, and plugins designed to encourage good coding practices. +analyzer: + errors: + use_build_context_synchronously: ignore include: package:flutter_lints/flutter.yaml linter: diff --git a/lib/constants/routes.dart b/lib/constants/routes.dart index 3008d73..16912eb 100644 --- a/lib/constants/routes.dart +++ b/lib/constants/routes.dart @@ -1,3 +1,4 @@ const loginRoute = '/login/'; const registerRoute = '/register/'; const notesRoute = '/notes/'; +const verifyEmailRoute = '/verify-email/'; diff --git a/lib/main.dart b/lib/main.dart index 8fa651c..0174963 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,6 +22,7 @@ void main() { loginRoute: (context) => const LoginView(), registerRoute: (context) => const RegisterView(), notesRoute: (context) => const NotesView(), + verifyEmailRoute: (context) => const VerifyEmailView(), }, ), ); diff --git a/lib/views/register_view.dart b/lib/views/register_view.dart index 5cbb3e9..90061e6 100644 --- a/lib/views/register_view.dart +++ b/lib/views/register_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 RegisterView extends StatefulWidget { const RegisterView({super.key}); @@ -59,19 +60,40 @@ class _RegisterViewState extends State { final email = _email.text; final password = _password.text; try { - final userCredential = await FirebaseAuth.instance - .createUserWithEmailAndPassword( - email: email, password: password); - devtools.log('User: ${userCredential.user}'); + await FirebaseAuth.instance.createUserWithEmailAndPassword( + email: email, + password: password, + ); + final user = FirebaseAuth.instance.currentUser; + await user?.sendEmailVerification(); + Navigator.of(context).pushNamed(verifyEmailRoute); } on FirebaseAuthException catch (e) { if (e.code == 'weak-password') { - devtools.log('The password provided is too weak.'); + await showErrorDialog( + context, + 'Weak Password', + ); } else if (e.code == 'email-already-in-use') { - devtools.log('The account already exists for that email.'); + await showErrorDialog( + context, + 'Email already in use', + ); } else if (e.code == 'invalid-email') { - devtools.log('The email provided is invalid.'); + await showErrorDialog( + context, + 'Invalid Email', + ); + } else { + await showErrorDialog( + context, + e.toString(), + ); } } catch (e) { + await showErrorDialog( + context, + e.toString(), + ); devtools.log(e.toString()); } }, diff --git a/lib/views/verify_email_view.dart b/lib/views/verify_email_view.dart index c2bb9df..ea87d97 100644 --- a/lib/views/verify_email_view.dart +++ b/lib/views/verify_email_view.dart @@ -1,5 +1,6 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; +import 'package:mynotes/constants/routes.dart'; class VerifyEmailView extends StatefulWidget { const VerifyEmailView({super.key}); @@ -18,7 +19,12 @@ class _VerifyEmailViewState extends State { backgroundColor: Colors.blue), body: Column( children: [ - const Text('Please verify your email address'), + const Text( + "we've sent an email to your email address, Please open it to verify your account", + ), + const Text( + 'If you did not receive the email, please press the button below to resend it.', + ), TextButton( onPressed: () async { final user = FirebaseAuth.instance.currentUser; @@ -26,7 +32,17 @@ class _VerifyEmailViewState extends State { }, child: const Text('Send verification email', style: TextStyle(color: Colors.blue)), - ) + ), + TextButton( + onPressed: () async { + await FirebaseAuth.instance.signOut(); + Navigator.of(context).pushNamedAndRemoveUntil( + registerRoute, + (route) => false, + ); + }, + child: const Text('Restart'), + ), ], ), );