From a91ad4fae2958cbb283872205dc01a0ebc43ac46 Mon Sep 17 00:00:00 2001 From: chendjou237 Date: Mon, 20 Jun 2022 09:05:30 +0100 Subject: [PATCH 1/2] re allocating the auth --- lib/screens/patients/sign_in.dart | 50 +++++++++++++++++-------------- lib/screens/patients/sign_up.dart | 9 +++--- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/screens/patients/sign_in.dart b/lib/screens/patients/sign_in.dart index b9374e2..548e076 100644 --- a/lib/screens/patients/sign_in.dart +++ b/lib/screens/patients/sign_in.dart @@ -13,8 +13,9 @@ import 'package:auto_route/auto_route.dart'; import '../../providers/providers.dart'; import '../../widgets/widgets.dart'; + class SignInPage extends ConsumerStatefulWidget { - const SignInPage({Key? key}) : super(key: key); + const SignInPage({Key? key}) : super(key: key); @override ConsumerState createState() => _SignInPageState(); @@ -23,16 +24,15 @@ class SignInPage extends ConsumerStatefulWidget { class _SignInPageState extends ConsumerState { final GlobalKey _scaffoldkey = new GlobalKey(); - // final key = + // final key = @override - Widget build(BuildContext context ) { + Widget build(BuildContext context) { final theme = Theme.of(context).textTheme; final auth = ref.read(authProvider); // ToastContext().init(context); final phoneController = TextEditingController(); final passwordController = TextEditingController(); return Scaffold( - key: _scaffoldkey, body: SafeArea( child: Container( @@ -51,24 +51,28 @@ class _SignInPageState extends ConsumerState { ), const SizedBox(height: 16), Text( - 'Enter your phone number and password', + 'Enter your email and password', style: theme.bodyText2, ), const SizedBox(height: 48), AuthField( validator: - RequiredValidator(errorText: 'password is required'), + RequiredValidator(errorText: 'email is required'), theme: theme, controller: phoneController, - hint: 'enter your phone number', + hint: 'enter your phone email', icon: const Icon( LineIcons.mobilePhone, ), - label: 'phone number', + label: 'email', obscureText: false), AuthField( validator: - RequiredValidator(errorText: 'password is required'), + MultiValidator([ + + RequiredValidator(errorText: 'email is required'), + EmailValidator(errorText: 'enter a correct email'), + ]), theme: theme, controller: passwordController, hint: 'enter your password', @@ -88,16 +92,18 @@ class _SignInPageState extends ConsumerState { ), const SizedBox(height: 24), AuthButton( - onTap: () { - // Navigator.pushNamed(context, "/"); + onTap: ()async { + // Navigator.pushNhone, pass: pass) // context.p - + if( await auth.signInUser(mail: phoneController.text, pass: passwordController.text)){ + context.pushRoute(HomeRouter()); + } }, label: "Login", ), const SizedBox(height: 16), GestureDetector( - onTap: () => Navigator.of(context).pushNamed('/sign_up'), + onTap: () => context.pushRoute(const SignUpRouter()), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, @@ -121,11 +127,11 @@ class _SignInPageState extends ConsumerState { ElevatedButton.icon( onPressed: () async { await auth.signInWithGoogle(context); - // Navigator.push( - // context, - // MaterialPageRoute( - // builder: (context) => HealPoint())); - + // Navigator.push( + // context, + // MaterialPageRoute( + // builder: (context) => HealPoint())); + // Toast.show( // "Somethin must kill a man", // backgroundColor: errorColor, @@ -147,8 +153,8 @@ class _SignInPageState extends ConsumerState { color: Colors.white, ), label: const Text("Connect As Doctor")), - const SizedBox(height: 16), - ElevatedButton.icon( + const SizedBox(height: 16), + ElevatedButton.icon( style: ElevatedButton.styleFrom( primary: Colors.purple, ), @@ -163,11 +169,11 @@ class _SignInPageState extends ConsumerState { ], ), ), - ),// + ), // ), ); } - + @override void dispose() { // ignore: todo diff --git a/lib/screens/patients/sign_up.dart b/lib/screens/patients/sign_up.dart index b58e84f..919b666 100644 --- a/lib/screens/patients/sign_up.dart +++ b/lib/screens/patients/sign_up.dart @@ -1,5 +1,6 @@ // ignore_for_file: use_key_in_widget_constructors, unused_local_variable +import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:form_field_validator/form_field_validator.dart'; @@ -14,6 +15,7 @@ import 'package:line_icons/line_icons.dart'; //import 'package:toast/toast.dart'; //import '../../models/models.dart'; +import '../../routes/route.gr.dart'; import '../../utilities/utilities.dart'; import '../../widgets/widgets.dart'; @@ -40,7 +42,7 @@ class _SignUpState extends ConsumerState { final otpVisibility = ref.watch(otpVisibilityProvider.state); final _auth = ref.read(authProvider.state); final _nameController = TextEditingController(); - + final _theme = Theme.of(context).textTheme; String phoneNumber = ''; final email = ref.read(emailProvider.state); @@ -125,7 +127,7 @@ class _SignUpState extends ConsumerState { // ); email.state = _emailController.text; name.state = _nameController.text; - Navigator.pushNamed(context, "/password"); + context.pushRoute(const PasswordRoute()); } // Toast.show( // "Something went wrong ", @@ -149,7 +151,7 @@ class _SignUpState extends ConsumerState { fontWeight: FontWeight.w600, ), ), - onTap: () => Navigator.pushNamed(context, "/sign_in"), + onTap: () => context.pushRoute(const SignInRoute()), ) ], ), @@ -163,7 +165,6 @@ class _SignUpState extends ConsumerState { @override void dispose() { - super.dispose(); } From acded96d40c9d0006a3225f1c30acf96dd277279 Mon Sep 17 00:00:00 2001 From: chendjou237 Date: Mon, 20 Jun 2022 09:46:09 +0100 Subject: [PATCH 2/2] auth update --- lib/functions/authentication.dart | 5 ++++- lib/screens/patients/password.dart | 12 +++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/functions/authentication.dart b/lib/functions/authentication.dart index 9cf9c6e..275c7ee 100644 --- a/lib/functions/authentication.dart +++ b/lib/functions/authentication.dart @@ -71,7 +71,7 @@ class Authentication { } //sign up the user and store his data to firestore - Future signupUser({ + Future signupUser({ required String mail, required String pass, required Patient patient, @@ -91,12 +91,15 @@ class Authentication { // Toast.show("error while signing up", // duration: Toast.lengthShort, backgroundColor: errorColor); }); + return true; } on FirebaseAuthException { + print('Something went wrong'); // Toast.show( // err.message ?? "Something went wrong !", // backgroundColor: errorColor, // duration: Toast.lengthShort, // ); + return false; } } diff --git a/lib/screens/patients/password.dart b/lib/screens/patients/password.dart index d58303d..8fc6317 100644 --- a/lib/screens/patients/password.dart +++ b/lib/screens/patients/password.dart @@ -1,5 +1,6 @@ // ignore_for_file: unused_local_variable +import 'package:auto_route/auto_route.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:form_field_validator/form_field_validator.dart'; @@ -10,6 +11,7 @@ import 'package:line_icons/line_icons.dart'; //import 'package:toast/toast.dart'; import '../../models/models.dart'; +import '../../routes/route.gr.dart'; import '../../widgets/widgets.dart'; class PasswordPage extends ConsumerStatefulWidget { @@ -105,7 +107,6 @@ class _PasswordScreenState extends ConsumerState { ), const SizedBox(height: 32), AuthButton( - onTap: () async { if (_formKey.currentState!.validate()) { // Toast.show( @@ -114,26 +115,23 @@ class _PasswordScreenState extends ConsumerState { // duration: Toast.lengthShort, // ); try { - - - await auth.signupUser( + if (await auth.signupUser( mail: email.state, context: context, pass: passwordController.text, patient: Patient( email: email.state, - names: name.state, phoneNumber: phone.state, ), - ); + )) context.pushRoute(const PhoneVerificationRoute()); // Navigator.pushNamed(context, "/heal"); // Toast.show( // "Something went wrong ", // backgroundColor: Colors.red, // duration: Toast.lengthShort, // ); - + } on FirebaseAuthException catch (e) { throw e.message ?? e.toString(); }