diff --git a/lib/services/auth_service.dart b/lib/services/auth_service.dart index f3c032c..620701d 100644 --- a/lib/services/auth_service.dart +++ b/lib/services/auth_service.dart @@ -1,7 +1,11 @@ import 'package:google_sign_in/google_sign_in.dart'; import 'package:firebase_auth/firebase_auth.dart'; +import 'package:retro_shopping/helpers/constants.dart'; +import 'package:flutter/material.dart'; class AuthenticationService { + final FirebaseAuth _auth = FirebaseAuth.instance; + static Future signInWithGoogle() async { final GoogleSignInAccount googleSignInAccount = await GoogleSignIn().signIn(); @@ -27,4 +31,102 @@ class AuthenticationService { static Future signOutGoogle() async { await GoogleSignIn().signOut(); } + + String userEmailValidation(String value, String errorMessage) { + if (value.isEmpty) { + return 'Required'; + } else if (errorMessage != null) { + if (!errorMessage.contains('Password') || + errorMessage.contains('Invalid Request')) { + return errorMessage; + } + return null; + } + return null; + } + + String userPasswordValidation(String value, String errorMessage) { + if (value.isEmpty) { + return 'Required'; + } else if (errorMessage != null) { + if (errorMessage.contains('Password') || + errorMessage.contains('Invalid Request')) { + return errorMessage; + } + return null; + } + return null; + } + + String userConfirmPasswordValidation( + String value, String password, String confirmPassword) { + if (value.isEmpty) { + return 'Required'; + } else if (password != confirmPassword) { + return 'Passwords Do Not Match'; + } + return null; + } + + Future userSignUp(String errorText, BuildContext context, + String email, String password) async { + String errorTemp = errorText; + try { + final UserCredential newUser = await _auth.createUserWithEmailAndPassword( + email: email, password: password); + if (newUser != null) { + Navigator.of(context) + .pushReplacementNamed(RouteConstant.DASHBOARD_SCREEN); + } + } catch (e) { + if (e.toString().contains('invalid-email')) { + errorTemp = 'Invalid Email'; + } else if (e.toString().contains('email-already-in-use')) { + errorTemp = 'User Already Exists'; + } else if (e.toString().contains('weak-password')) { + errorTemp = 'Password Too Short'; + } else { + errorTemp = 'Invalid Request'; + } + return errorTemp; + } + return null; + } + + Future userLogin(String errorText, BuildContext context, String email, + String password) async { + String errorTemp = errorText; + try { + final UserCredential existingUser = await _auth + .signInWithEmailAndPassword(email: email, password: password); + if (existingUser != null) { + Navigator.of(context).pushReplacementNamed( + RouteConstant.DASHBOARD_SCREEN, + ); + } + } catch (e) { + if (e.toString().contains('invalid-email')) { + errorTemp = 'Invalid Email'; + } else if (e.toString().contains('user-not-found')) { + errorTemp = 'User Not Found'; + } else if (e.toString().contains('wrong-password')) { + errorTemp = 'Incorrect Password'; + } else { + errorTemp = 'Invalid Request'; + } + return errorTemp; + } + return null; + } + + Future userSignOut(BuildContext context) async { + final User user = _auth.currentUser; + if (user != null) { + await _auth.signOut(); + Navigator.of(context).pushNamedAndRemoveUntil( + RouteConstant.LOGIN_SCREEN, + (Route route) => false, + ); + } + } } diff --git a/lib/views/auth/login_view.dart b/lib/views/auth/login_view.dart index 20632dc..f0afbde 100644 --- a/lib/views/auth/login_view.dart +++ b/lib/views/auth/login_view.dart @@ -16,6 +16,20 @@ TextEditingController _emailController = TextEditingController(); TextEditingController _passwordController = TextEditingController(); class LoginScreenState extends State { + final GlobalKey _formKey = GlobalKey(); + final AuthenticationService _authenticationService = AuthenticationService(); + + String email; + String password; + String errorMessage; + + @override + void dispose() { + _emailController.clear(); + _passwordController.clear(); + super.dispose(); + } + @override Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; @@ -30,87 +44,54 @@ class LoginScreenState extends State { width: width * 0.87, child: Center( child: SingleChildScrollView( - child: Column( - // ignore: always_specify_types - children: [ - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 10), - child: Row( + child: Form( + key: _formKey, + child: Column( + // ignore: always_specify_types + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 10), + child: Row( + // ignore: always_specify_types, prefer_const_literals_to_create_immutables + children: [ + // ignore: prefer_const_literals_to_create_immutables, + const Text( + 'Login', + style: TextStyle( + fontSize: 40, + color: Colors.white, + fontFamily: 'pix M 8pt', + fontWeight: FontWeight.bold), + ), + ], + ), + ), + SizedBox( + height: height * 0.011, + ), + Row( // ignore: always_specify_types, prefer_const_literals_to_create_immutables children: [ - // ignore: prefer_const_literals_to_create_immutables, - const Text( - 'Login', - style: TextStyle( - fontSize: 40, + const Padding( + padding: + EdgeInsets.only(left: 20.0, right: 20.0), + child: Text( + 'Welcome back,\nPlease login to your account', + style: TextStyle( + fontSize: 20, color: Colors.white, fontFamily: 'pix M 8pt', - fontWeight: FontWeight.bold), - ), - ], - ), - ), - SizedBox( - height: height * 0.011, - ), - Row( - // ignore: always_specify_types, prefer_const_literals_to_create_immutables - children: [ - const Padding( - padding: EdgeInsets.only(left: 20.0, right: 20.0), - child: Text( - 'Welcome back,\nPlease login to your account', - style: TextStyle( - fontSize: 20, - color: Colors.white, - fontFamily: 'pix M 8pt', - //fontWeight: FontWeight.bold - ), - ), - ), - ], - ), - SizedBox( - height: height * 0.020, - ), - Stack( - // ignore: always_specify_types - children: [ - Transform.translate( - offset: const Offset(25, 10), - child: Container( - color: Colors.black, - width: width * 0.77, - height: height * 0.065, - ), - ), - Padding( - padding: const EdgeInsets.only( - left: 20.0, right: 20.0), - // ignore: sized_box_for_whitespace - child: Container( - height: height * 0.07, - child: TextField( - controller: _emailController, - decoration: const InputDecoration( - labelText: 'Email Address', - labelStyle: TextStyle( - fontSize: 20.0, color: Colors.black), - filled: true, - fillColor: Colors.white, - border: OutlineInputBorder( - borderRadius: BorderRadius.zero), + //fontWeight: FontWeight.bold ), ), ), - ), - ], - ), - SizedBox( - height: height * 0.030, - ), - Stack( + ], + ), + SizedBox( + height: height * 0.020, + ), + Stack( // ignore: always_specify_types children: [ Transform.translate( @@ -127,129 +108,192 @@ class LoginScreenState extends State { // ignore: sized_box_for_whitespace child: Container( height: height * 0.07, - child: TextField( - controller: _passwordController, - decoration: const InputDecoration( - labelText: 'Password', - labelStyle: TextStyle( - fontSize: 20.0, - color: Colors.black), - filled: true, - fillColor: Colors.white, - border: OutlineInputBorder( - borderRadius: - BorderRadius.zero))), - ), - ), - ]), - SizedBox( - height: height * 0.030, - ), - Row( - // ignore: always_specify_types - children: [ - Padding( - padding: const EdgeInsets.only( - left: 20.0, right: 20.0), - child: InkWell( - onTap: () { - debugPrint('Login!'); - // ignore: always_specify_types - Navigator.of(context).pushNamed( - RouteConstant.DASHBOARD_SCREEN, - ); - }, - child: RetroButton( - upperColor: Colors.black, - lowerColor: Colors.white, - height: height * 0.065, - width: width * 0.40, - borderColor: Colors.white, - child: const Center( - child: Text( - 'Login', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.white, - ), + child: TextFormField( + onChanged: (String value) { + email = value; + }, + validator: (String value) => + _authenticationService + .userEmailValidation( + value, errorMessage), + controller: _emailController, + keyboardType: TextInputType.emailAddress, + decoration: const InputDecoration( + labelText: 'Email Address', + labelStyle: TextStyle( + fontSize: 20.0, color: Colors.black), + filled: true, + fillColor: Colors.white, + border: OutlineInputBorder( + borderRadius: BorderRadius.zero), ), ), ), ), - ), - ], - ), - SizedBox( - height: height * 0.040, - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 115), - child: Row( + ], + ), + SizedBox( + height: height * 0.030, + ), + Stack( // ignore: always_specify_types children: [ - InkWell( - onTap: () { - debugPrint('Navigate to google!'); - AuthenticationService.signInWithGoogle() - .then( - (String result) { - if (result != null) { - Navigator.of(context) - .pushReplacementNamed( - RouteConstant.DASHBOARD_SCREEN, - ); - } - }, - ); - }, - // ignore: sized_box_for_whitespace + Transform.translate( + offset: const Offset(25, 10), child: Container( - width: 45, - height: 45, - child: Image.asset( - 'assets/items/google.png', - )), - ), - SizedBox( - width: width * 0.05, + color: Colors.black, + width: width * 0.77, + height: height * 0.065, + ), ), - InkWell( - onTap: () { - debugPrint('Navigate to facebook!'); - }, + Padding( + padding: const EdgeInsets.only( + left: 20.0, right: 20.0), // ignore: sized_box_for_whitespace child: Container( - width: 45, - height: 45, - child: - Image.asset('assets/items/fb.png')), + height: height * 0.07, + child: TextFormField( + onChanged: (String value) { + password = value; + }, + validator: (String value) { + return _authenticationService + .userPasswordValidation( + value, errorMessage); + }, + controller: _passwordController, + keyboardType: + TextInputType.visiblePassword, + obscureText: true, + decoration: const InputDecoration( + labelText: 'Password', + labelStyle: TextStyle( + fontSize: 20.0, + color: Colors.black), + filled: true, + fillColor: Colors.white, + border: OutlineInputBorder( + borderRadius: + BorderRadius.zero))), + ), ), ]), - ), - const SizedBox(height: 10.0), - Row( - //LINK TO SIGN UP PAGE - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text("Don't have an account?"), - const SizedBox(width: 5.0), - InkWell( - onTap: () { - // ignore: always_specify_types - Navigator.of(context) - .pushNamed(RouteConstant.SIGN_UP_SCREEN); - }, - child: const Text( - 'SignUp', - style: TextStyle( - color: Colors.black, + SizedBox( + height: height * 0.030, + ), + Row( + // ignore: always_specify_types + children: [ + Padding( + padding: const EdgeInsets.only( + left: 20.0, right: 20.0), + child: InkWell( + onTap: () async { + debugPrint('Login!'); + errorMessage = null; + if (_formKey.currentState.validate()) { + errorMessage = + await _authenticationService + .userLogin(errorMessage, context, + email, password); + if (errorMessage != null) { + _formKey.currentState.validate(); + } + } + }, + child: RetroButton( + upperColor: Colors.black, + lowerColor: Colors.white, + height: height * 0.065, + width: width * 0.40, + borderColor: Colors.white, + child: const Center( + child: Text( + 'Login', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + ), + ), ), ), - ) - ], - ), - ], + ], + ), + SizedBox( + height: height * 0.040, + ), + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 115), + child: Row( + // ignore: always_specify_types + children: [ + InkWell( + onTap: () { + debugPrint('Navigate to google!'); + AuthenticationService.signInWithGoogle() + .then( + (String result) { + if (result != null) { + Navigator.of(context) + .pushReplacementNamed( + RouteConstant.DASHBOARD_SCREEN, + ); + } + }, + ); + }, + // ignore: sized_box_for_whitespace + child: Container( + width: 45, + height: 45, + child: Image.asset( + 'assets/items/google.png', + )), + ), + SizedBox( + width: width * 0.05, + ), + InkWell( + onTap: () { + debugPrint('Navigate to facebook!'); + }, + // ignore: sized_box_for_whitespace + child: Container( + width: 45, + height: 45, + child: + Image.asset('assets/items/fb.png')), + ), + ]), + ), + const SizedBox(height: 10.0), + Row( + //LINK TO SIGN UP PAGE + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text("Don't have an account?"), + const SizedBox(width: 5.0), + InkWell( + onTap: () { + // ignore: always_specify_types + Navigator.of(context) + .pushNamed(RouteConstant.SIGN_UP_SCREEN); + }, + child: const Text( + 'SignUp', + style: TextStyle( + color: Colors.black, + ), + ), + ) + ], + ), + ], + ), ), ), )), diff --git a/lib/views/auth/signup_view.dart b/lib/views/auth/signup_view.dart index a0057da..137d8cb 100644 --- a/lib/views/auth/signup_view.dart +++ b/lib/views/auth/signup_view.dart @@ -13,8 +13,25 @@ class SignUpScreen extends StatefulWidget { TextEditingController _emailController = TextEditingController(); TextEditingController _passwordController = TextEditingController(); +TextEditingController _confirmPasswordController = TextEditingController(); class SignUpScreenState extends State { + final GlobalKey _formKey = GlobalKey(); + final AuthenticationService _authenticationService = AuthenticationService(); + + String email; + String password; + String errorMessage; + String confirmPassword; + + @override + void dispose() { + _emailController.clear(); + _passwordController.clear(); + _confirmPasswordController.clear(); + super.dispose(); + } + @override Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; @@ -43,240 +60,288 @@ class SignUpScreenState extends State { const BoxDecoration(color: RelicColors.primaryColor), child: Center( child: SingleChildScrollView( - child: Column( - // ignore: always_specify_types - children: [ - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 10), - child: Row( + child: Form( + key: _formKey, + child: Column( + // ignore: always_specify_types + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 10), + child: Row( + // ignore: always_specify_types, prefer_const_literals_to_create_immutables + children: [ + // ignore: prefer_const_literals_to_create_immutables, + const Text( + 'SignUp', + style: TextStyle( + fontSize: 40, + color: Colors.white, + fontFamily: 'pix M 8pt', + fontWeight: FontWeight.bold), + ), + ], + ), + ), + SizedBox( + height: height * 0.011, + ), + Row( // ignore: always_specify_types, prefer_const_literals_to_create_immutables children: [ - // ignore: prefer_const_literals_to_create_immutables, - const Text( - 'SignUp', - style: TextStyle( - fontSize: 40, + const Padding( + padding: EdgeInsets.only( + left: 20.0, right: 20.0), + child: Text( + 'Get Started,\nCreate a new account', + style: TextStyle( + fontSize: 20, color: Colors.white, fontFamily: 'pix M 8pt', - fontWeight: FontWeight.bold), + //fontWeight: FontWeight.bold + ), + ), ), ], ), - ), - SizedBox( - height: height * 0.011, - ), - Row( - // ignore: always_specify_types, prefer_const_literals_to_create_immutables - children: [ - const Padding( - padding: - EdgeInsets.only(left: 20.0, right: 20.0), - child: Text( - 'Get Started,\nCreate a new account', - style: TextStyle( - fontSize: 20, - color: Colors.white, - fontFamily: 'pix M 8pt', - //fontWeight: FontWeight.bold + SizedBox( + height: height * 0.020, + ), + Stack( + // ignore: always_specify_types + children: [ + Transform.translate( + offset: const Offset(25, 10), + child: Container( + color: Colors.black, + width: width * 0.77, + height: height * 0.065, + ), ), - ), - ), - ], - ), - SizedBox( - height: height * 0.020, - ), - Stack( - // ignore: always_specify_types - children: [ - Transform.translate( - offset: const Offset(25, 10), - child: Container( - color: Colors.black, - width: width * 0.77, - height: height * 0.065, + Padding( + padding: const EdgeInsets.only( + left: 20.0, right: 20.0), + // ignore: sized_box_for_whitespace + child: Container( + height: height * 0.07, + child: TextFormField( + onChanged: (String value) { + email = value; + }, + validator: (String value) { + return _authenticationService + .userEmailValidation( + value, errorMessage); + }, + controller: _emailController, + keyboardType: + TextInputType.emailAddress, + decoration: const InputDecoration( + labelText: 'Email Address', + labelStyle: TextStyle( + fontSize: 20.0, + color: Colors.black), + filled: true, + fillColor: Colors.white, + border: OutlineInputBorder( + borderRadius: + BorderRadius.zero))), + ), ), - ), - Padding( - padding: const EdgeInsets.only( - left: 20.0, right: 20.0), - // ignore: sized_box_for_whitespace - child: Container( - height: height * 0.07, - child: TextField( - controller: _emailController, - decoration: const InputDecoration( - labelText: 'Email Address', - labelStyle: TextStyle( - fontSize: 20.0, - color: Colors.black), - filled: true, - fillColor: Colors.white, - border: OutlineInputBorder( - borderRadius: - BorderRadius.zero))), + ]), + SizedBox( + height: height * 0.030, + ), + Stack( + // ignore: always_specify_types + children: [ + Transform.translate( + offset: const Offset(25, 10), + child: Container( + color: Colors.black, + width: width * 0.77, + height: height * 0.065, + ), ), - ), - ]), - SizedBox( - height: height * 0.030, - ), - Stack( - // ignore: always_specify_types - children: [ - Transform.translate( - offset: const Offset(25, 10), - child: Container( - color: Colors.black, - width: width * 0.77, - height: height * 0.065, + Padding( + padding: const EdgeInsets.only( + left: 20.0, right: 20.0), + // ignore: sized_box_for_whitespace + child: Container( + height: height * 0.07, + child: TextFormField( + onChanged: (String value) { + password = value; + }, + validator: (String value) { + return _authenticationService + .userPasswordValidation( + value, errorMessage); + }, + controller: _passwordController, + keyboardType: + TextInputType.visiblePassword, + obscureText: true, + decoration: const InputDecoration( + labelText: 'Password', + labelStyle: TextStyle( + fontSize: 20.0, + color: Colors.black), + filled: true, + fillColor: Colors.white, + border: OutlineInputBorder( + borderRadius: + BorderRadius.zero))), + ), ), - ), - Padding( - padding: const EdgeInsets.only( - left: 20.0, right: 20.0), - // ignore: sized_box_for_whitespace - child: Container( - height: height * 0.07, - child: TextField( - controller: _passwordController, - decoration: const InputDecoration( - labelText: 'Password', - labelStyle: TextStyle( - fontSize: 20.0, - color: Colors.black), - filled: true, - fillColor: Colors.white, - border: OutlineInputBorder( - borderRadius: - BorderRadius.zero))), + ]), + SizedBox( + height: height * 0.030, + ), + Stack( + // ignore: always_specify_types + children: [ + Transform.translate( + offset: const Offset(25, 10), + child: Container( + color: Colors.black, + width: width * 0.77, + height: height * 0.065, + ), ), - ), - ]), - SizedBox( - height: height * 0.030, - ), - Stack( + Padding( + padding: const EdgeInsets.only( + left: 20.0, right: 20.0), + // ignore: sized_box_for_whitespace + child: Container( + height: height * 0.07, + child: TextFormField( + onChanged: (String value) { + confirmPassword = value; + }, + validator: (String value) { + return _authenticationService + .userConfirmPasswordValidation( + value, + password, + confirmPassword); + }, + controller: + _confirmPasswordController, + keyboardType: + TextInputType.visiblePassword, + obscureText: true, + decoration: const InputDecoration( + labelText: 'Confirm Password', + labelStyle: TextStyle( + fontSize: 20.0, + color: Colors.black), + filled: true, + fillColor: Colors.white, + border: OutlineInputBorder( + borderRadius: + BorderRadius.zero))), + ), + ), + ]), + SizedBox( + height: height * 0.030, + ), + Row( // ignore: always_specify_types children: [ - Transform.translate( - offset: const Offset(25, 10), - child: Container( - color: Colors.black, - width: width * 0.77, - height: height * 0.065, - ), - ), Padding( padding: const EdgeInsets.only( left: 20.0, right: 20.0), - // ignore: sized_box_for_whitespace - child: Container( - height: height * 0.07, - child: TextField( - controller: _passwordController, - decoration: const InputDecoration( - labelText: 'Confirm Password', - labelStyle: TextStyle( - fontSize: 20.0, - color: Colors.black), - filled: true, - fillColor: Colors.white, - border: OutlineInputBorder( - borderRadius: - BorderRadius.zero))), - ), - ), - ]), - SizedBox( - height: height * 0.030, - ), - Row( - // ignore: always_specify_types - children: [ - Padding( - padding: const EdgeInsets.only( - left: 20.0, right: 20.0), - child: InkWell( - onTap: () { - debugPrint('SignUp!!'); - // ignore: always_specify_types - Navigator.of(context).pushNamed( - RouteConstant.LOGIN_SCREEN); - }, - child: RetroButton( - upperColor: Colors.black, - lowerColor: Colors.white, - height: height * 0.065, - width: width * 0.40, - borderColor: Colors.white, - child: const Center( - child: Text( - 'SignUp', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.white, + child: InkWell( + onTap: () async { + debugPrint('SignUp!!'); + errorMessage = null; + if (_formKey.currentState.validate()) { + errorMessage = + await _authenticationService + .userSignUp(errorMessage, + context, email, password); + if (errorMessage != null) { + _formKey.currentState.validate(); + } + } + }, + child: RetroButton( + upperColor: Colors.black, + lowerColor: Colors.white, + height: height * 0.065, + width: width * 0.40, + borderColor: Colors.white, + child: const Center( + child: Text( + 'SignUp', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.white, + ), ), ), ), ), ), - ), - ], - ), - SizedBox( - height: height * 0.040, - ), - Padding( - padding: - const EdgeInsets.symmetric(horizontal: 115), - child: Row( - // ignore: always_specify_types - children: [ - InkWell( - onTap: () { - debugPrint('Navigate to google!'); - AuthenticationService.signInWithGoogle() - .then( - (String result) { - if (result != null) { - Navigator.of(context) - .pushNamedAndRemoveUntil( - RouteConstant.DASHBOARD_SCREEN, - (Route route) => false, - ); - } - }, - ); - }, - // ignore: sized_box_for_whitespace - child: Container( - width: 45, - height: 45, - child: Image.asset( - 'assets/items/google.png', - )), - ), - SizedBox( - width: width * 0.05, - ), - InkWell( - onTap: () { - debugPrint('Navigate to facebook!'); - }, - // ignore: sized_box_for_whitespace - child: Container( - width: 45, - height: 45, - child: Image.asset( - 'assets/items/fb.png')), - ), - ]), - ), - ], + ], + ), + SizedBox( + height: height * 0.040, + ), + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 115), + child: Row( + // ignore: always_specify_types + children: [ + InkWell( + onTap: () { + debugPrint('Navigate to google!'); + AuthenticationService + .signInWithGoogle() + .then( + (String result) { + if (result != null) { + Navigator.of(context) + .pushNamedAndRemoveUntil( + RouteConstant + .DASHBOARD_SCREEN, + (Route route) => + false, + ); + } + }, + ); + }, + // ignore: sized_box_for_whitespace + child: Container( + width: 45, + height: 45, + child: Image.asset( + 'assets/items/google.png', + )), + ), + SizedBox( + width: width * 0.05, + ), + InkWell( + onTap: () { + debugPrint('Navigate to facebook!'); + }, + // ignore: sized_box_for_whitespace + child: Container( + width: 45, + height: 45, + child: Image.asset( + 'assets/items/fb.png')), + ), + ]), + ), + ], + ), ), ), )), diff --git a/lib/views/drawer_view.dart b/lib/views/drawer_view.dart index 5791030..6881232 100644 --- a/lib/views/drawer_view.dart +++ b/lib/views/drawer_view.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:retro_shopping/helpers/constants.dart'; import 'package:retro_shopping/services/auth_service.dart'; import '../widgets/drawer_item.dart'; +import 'package:firebase_auth/firebase_auth.dart'; class DrawerWidget extends StatefulWidget { final PageController pageController; @@ -15,6 +16,9 @@ class DrawerWidget extends StatefulWidget { } class _DrawerWidgetState extends State { + final FirebaseAuth _auth = FirebaseAuth.instance; + AuthenticationService _authenticationService = AuthenticationService(); + void goToScreen(int index) { if (widget.pageController.initialPage == index) { Navigator.of(context).pop(); @@ -70,7 +74,8 @@ class _DrawerWidgetState extends State { DrawerItem( icon: Icons.logout, title: 'LOG OUT', - onTap: () { + onTap: () async { + await _authenticationService.userSignOut(context); AuthenticationService.signOutGoogle().then( (void res) { Navigator.of(context).pushNamedAndRemoveUntil(