Skip to content

Commit

Permalink
Merge pull request #12 from chendjou237/developement
Browse files Browse the repository at this point in the history
re allocating the auth
  • Loading branch information
chendjou237 authored Jun 20, 2022
2 parents 76cc17e + acded96 commit ff496f3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 34 deletions.
5 changes: 4 additions & 1 deletion lib/functions/authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Authentication {
}

//sign up the user and store his data to firestore
Future<void> signupUser({
Future<bool> signupUser({
required String mail,
required String pass,
required Patient patient,
Expand All @@ -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;
}
}

Expand Down
12 changes: 5 additions & 7 deletions lib/screens/patients/password.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -105,7 +107,6 @@ class _PasswordScreenState extends ConsumerState<PasswordPage> {
),
const SizedBox(height: 32),
AuthButton(

onTap: () async {
if (_formKey.currentState!.validate()) {
// Toast.show(
Expand All @@ -114,26 +115,23 @@ class _PasswordScreenState extends ConsumerState<PasswordPage> {
// 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();
}
Expand Down
50 changes: 28 additions & 22 deletions lib/screens/patients/sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<SignInPage> createState() => _SignInPageState();
Expand All @@ -23,16 +24,15 @@ class SignInPage extends ConsumerStatefulWidget {
class _SignInPageState extends ConsumerState<SignInPage> {
final GlobalKey<ScaffoldState> _scaffoldkey = new GlobalKey<ScaffoldState>();

// 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(
Expand All @@ -51,24 +51,28 @@ class _SignInPageState extends ConsumerState<SignInPage> {
),
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',
Expand All @@ -88,16 +92,18 @@ class _SignInPageState extends ConsumerState<SignInPage> {
),
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,
Expand All @@ -121,11 +127,11 @@ class _SignInPageState extends ConsumerState<SignInPage> {
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,
Expand All @@ -147,8 +153,8 @@ class _SignInPageState extends ConsumerState<SignInPage> {
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,
),
Expand All @@ -163,11 +169,11 @@ class _SignInPageState extends ConsumerState<SignInPage> {
],
),
),
),//
), //
),
);
}

@override
void dispose() {
// ignore: todo
Expand Down
9 changes: 5 additions & 4 deletions lib/screens/patients/sign_up.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

Expand All @@ -40,7 +42,7 @@ class _SignUpState extends ConsumerState<SignUpPage> {
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);
Expand Down Expand Up @@ -125,7 +127,7 @@ class _SignUpState extends ConsumerState<SignUpPage> {
// );
email.state = _emailController.text;
name.state = _nameController.text;
Navigator.pushNamed(context, "/password");
context.pushRoute(const PasswordRoute());
}
// Toast.show(
// "Something went wrong ",
Expand All @@ -149,7 +151,7 @@ class _SignUpState extends ConsumerState<SignUpPage> {
fontWeight: FontWeight.w600,
),
),
onTap: () => Navigator.pushNamed(context, "/sign_in"),
onTap: () => context.pushRoute(const SignInRoute()),
)
],
),
Expand All @@ -163,7 +165,6 @@ class _SignUpState extends ConsumerState<SignUpPage> {

@override
void dispose() {

super.dispose();
}

Expand Down

0 comments on commit ff496f3

Please sign in to comment.