From c85b82d5538e310477b2ddd581fcc95e6ae7e862 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Tue, 8 Sep 2020 12:24:24 +0300 Subject: [PATCH] fix login issue --- .../viewModels/authentication_view_model.dart | 5 ++- lib/locator.dart | 3 +- lib/pages/authentication/login_page.dart | 44 +++++++++---------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/core/viewModels/authentication_view_model.dart b/lib/core/viewModels/authentication_view_model.dart index 96f3dc0..1f89a60 100644 --- a/lib/core/viewModels/authentication_view_model.dart +++ b/lib/core/viewModels/authentication_view_model.dart @@ -69,7 +69,10 @@ class AuthenticationViewModel with ChangeNotifier { isError = true; notifyListeners(); } else { - sharedPref.setObject( + isLoading = false; + isError = false; + isLogin = true; + await sharedPref.setObject( USER_PROFILE, _authenticationService.authenticatedUser); sharedPref.setString(TOKEN, _authenticationService.token); user = _authenticationService.authenticatedUser; diff --git a/lib/locator.dart b/lib/locator.dart index 66afadd..d1b2ba3 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -3,7 +3,6 @@ import 'package:get_it/get_it.dart'; import 'core/service/authentication_service.dart'; import 'core/service/hospital_service.dart'; import 'core/service/orders_service.dart'; -import 'core/viewModels/authentication_view_model.dart'; import 'core/viewModels/hospital_view_model.dart'; import 'core/viewModels/orders_view_model.dart'; @@ -18,6 +17,6 @@ void setupLocator() { /// View Model locator.registerFactory(() => HospitalViewModel()); - locator.registerFactory(() => AuthenticationViewModel()); + // locator.registerFactory(() => AuthenticationViewModel()); locator.registerFactory(() => OrdersViewModel()); } diff --git a/lib/pages/authentication/login_page.dart b/lib/pages/authentication/login_page.dart index 5d45d5c..79046f7 100644 --- a/lib/pages/authentication/login_page.dart +++ b/lib/pages/authentication/login_page.dart @@ -2,11 +2,9 @@ import 'package:driverapp/app-icons/driver_app_icons.dart'; import 'package:driverapp/core/model/authentication/login_request.dart'; import 'package:driverapp/core/viewModels/authentication_view_model.dart'; import 'package:driverapp/core/viewModels/project_view_model.dart'; -import 'package:driverapp/pages/dashboard/dashboard_screen.dart'; import 'package:driverapp/uitl/translations_delegate_base.dart'; import 'package:driverapp/uitl/utils.dart'; import 'package:driverapp/widgets/buttons/secondary_button.dart'; -import 'package:driverapp/widgets/data_display/circle-container.dart'; import 'package:driverapp/widgets/input/text_field.dart'; import 'package:driverapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/cupertino.dart'; @@ -25,16 +23,27 @@ class LoginPage extends StatelessWidget { Widget build(BuildContext context) { projectViewModel = Provider.of(context); authenticationViewModel = Provider.of(context); + + login() async { + if (loginFormKey.currentState.validate()) { + loginFormKey.currentState.save(); + await authenticationViewModel.login(loginRequest); + if (authenticationViewModel.isError) { + Utils.showErrorToast(authenticationViewModel.error); + } + } + } + return AnimatedSwitcher( duration: Duration(microseconds: 350), - child: AppScaffold( - isShowAppBar: false, - body: SingleChildScrollView( - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - FractionallySizedBox( + child: AppScaffold( + isShowAppBar: false, + body: SingleChildScrollView( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FractionallySizedBox( widthFactor: 0.80, child: Column( children: [ @@ -237,7 +246,7 @@ class LoginPage extends StatelessWidget { SecondaryButton( label: TranslationBase.of(context).login, onTap: () { - login(context); + login(); }, disabled: authenticationViewModel.isLoading, loading: authenticationViewModel.isLoading, @@ -255,17 +264,4 @@ class LoginPage extends StatelessWidget { ); } - login(BuildContext context) async { - if (loginFormKey.currentState.validate()) { - loginFormKey.currentState.save(); - await authenticationViewModel.login(loginRequest); - if (authenticationViewModel.isError) { - Utils.showErrorToast(authenticationViewModel.error); - } else { - Navigator.push( - context, - MaterialPageRoute(builder: (context) => DashboardScreen())); - } - } - } }