From 41c66fc8ffcbcdeebe3f91a0983d7315c0264b69 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 7 Sep 2020 09:31:44 +0300 Subject: [PATCH] fix auth issue --- lib/core/service/UserDetailsService.dart | 3 + lib/core/service/client/base_app_client.dart | 1 + .../viewModels/authentication_view_model.dart | 58 +- lib/locator.dart | 2 + lib/main.dart | 11 +- lib/pages/authentication/login_page.dart | 401 ++++--- lib/pages/dashboard/dashboard_screen.dart | 988 ++++++++++-------- lib/pages/delivery/information_page.dart | 2 +- lib/root_page.dart | 23 +- 9 files changed, 829 insertions(+), 660 deletions(-) create mode 100644 lib/core/service/UserDetailsService.dart diff --git a/lib/core/service/UserDetailsService.dart b/lib/core/service/UserDetailsService.dart new file mode 100644 index 0000000..dbb79e3 --- /dev/null +++ b/lib/core/service/UserDetailsService.dart @@ -0,0 +1,3 @@ +import 'package:driverapp/core/service/base_service.dart'; + +class UserDetailsService extends BaseService {} diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index 9b5834a..d5f6d13 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -34,6 +34,7 @@ class BaseAppClient { body['TokenID'] = token; body['MobileNo'] = doctorProfile?.mobileNumber; body['Channel'] = CHANNEL; + body['VersionID'] = 8.3; } diff --git a/lib/core/viewModels/authentication_view_model.dart b/lib/core/viewModels/authentication_view_model.dart index b64f49c..336ddd5 100644 --- a/lib/core/viewModels/authentication_view_model.dart +++ b/lib/core/viewModels/authentication_view_model.dart @@ -1,22 +1,58 @@ import 'package:driverapp/config/shared_pref_kay.dart'; -import 'package:driverapp/core/enum/viewstate.dart'; +import 'package:driverapp/core/model/authentication/authenticated_user.dart'; import 'package:driverapp/core/model/authentication/login_request.dart'; import 'package:driverapp/core/service/authentication_service.dart'; import 'package:driverapp/core/service/client/base_app_client.dart'; -import 'package:driverapp/core/viewModels/base_view_model.dart'; +import 'package:flutter/cupertino.dart'; import '../../locator.dart'; enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } -class AuthenticationViewModel extends BaseViewModel { - AuthenticationService _authenticationService = locator(); +class AuthenticationViewModel with ChangeNotifier { + AuthenticationService _authenticationService = + locator(); + AuthenticatedUser user; + bool isLogin = false; + bool isLoading = false; + bool isError = false; + String error; + + AuthenticationViewModel() { + getUser(); + } + + getUser() async { + var asd = ""; + if (user == null) { + isLoading = true; + notifyListeners(); + var userProfile = await sharedPref.getObject(USER_PROFILE); + if (userProfile != null) { + user = AuthenticatedUser.fromJson( + await sharedPref.getObject(USER_PROFILE)); + isLogin = true; + isLoading = false; + notifyListeners(); + } else { + isLogin = false; + isLoading = false; + notifyListeners(); + } + } +// else +// { +// isLogin = true; +// isLoading = false; +// notifyListeners(); +// } + } APP_STATUS get status { - if (state == ViewState.Busy || state == ViewState.BusyLocal) { + if (isLoading) { return APP_STATUS.LOADING; } else { - if ( user != null) { + if (isLogin) { return APP_STATUS.AUTHENTICATED; } else { return APP_STATUS.UNAUTHENTICATED; @@ -25,16 +61,20 @@ class AuthenticationViewModel extends BaseViewModel { } login(LoginRequest loginRequest) async { - setState(ViewState.BusyLocal); + isLoading = true; + notifyListeners(); await _authenticationService.login(loginRequest); if (_authenticationService.hasError) { error = _authenticationService.error; - setState(ViewState.ErrorLocal); + isLoading = false; + isError = true; + notifyListeners(); } else { sharedPref.setObject( USER_PROFILE, _authenticationService.authenticatedUser); sharedPref.setString(TOKEN, _authenticationService.token); - setState(ViewState.Idle); + user = _authenticationService.authenticatedUser; + notifyListeners(); } } } diff --git a/lib/locator.dart b/lib/locator.dart index 66afadd..729f658 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -20,4 +20,6 @@ void setupLocator() { locator.registerFactory(() => HospitalViewModel()); locator.registerFactory(() => AuthenticationViewModel()); locator.registerFactory(() => OrdersViewModel()); + //locator.registerSingleton(AuthenticatedUser(),instanceName: "user",signalsReady: true); +// locator.registerSingleton(() => BaseViewModel()); } diff --git a/lib/main.dart b/lib/main.dart index d181377..befeb98 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:provider/provider.dart'; import 'config/size_config.dart'; +import 'core/viewModels/authentication_view_model.dart'; import 'core/viewModels/project_view_model.dart'; import 'locator.dart'; @@ -25,7 +26,15 @@ class MyApp extends StatelessWidget { providers: [ ChangeNotifierProvider( create: (context) => ProjectViewModel(), - ) + ), + ChangeNotifierProvider( + create: (context) => AuthenticationViewModel(), + ), + +// ChangeNotifierProxyProvider( +// update: (_, auth, payments) => payments..getUser(), +// create: (_) => AuthenticationViewModel(), +// ), ], child: Consumer( builder: (context, projectProvider, child) => MaterialApp( diff --git a/lib/pages/authentication/login_page.dart b/lib/pages/authentication/login_page.dart index 657a9cd..24edecd 100644 --- a/lib/pages/authentication/login_page.dart +++ b/lib/pages/authentication/login_page.dart @@ -1,9 +1,7 @@ import 'package:driverapp/app-icons/driver_app_icons.dart'; -import 'package:driverapp/core/enum/viewstate.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/base/base_view.dart'; import 'package:driverapp/pages/dashboard/dashboard_screen.dart'; import 'package:driverapp/uitl/translations_delegate_base.dart'; import 'package:driverapp/uitl/utils.dart'; @@ -21,244 +19,245 @@ class LoginPage extends StatelessWidget { LoginRequest loginRequest = LoginRequest(); final loginFormKey = GlobalKey(); ProjectViewModel projectViewModel; + AuthenticationViewModel authenticationViewModel; @override Widget build(BuildContext context) { projectViewModel = Provider.of(context); + authenticationViewModel = Provider.of(context); return AnimatedSwitcher( duration: Duration(microseconds: 350), - child: BaseView( - builder: (_, model, widget) => - AppScaffold( - isShowAppBar: false, - body: SingleChildScrollView( - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - FractionallySizedBox( - widthFactor: 0.80, - child: Column( - children: [ - SizedBox( - height: 40, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - child: Icon( - DriverApp.logo, - size: 70, - color: Theme.of(context).primaryColor, - ), - margin: EdgeInsets.only( - right: projectViewModel.isArabic - ? 0 - : MediaQuery.of(context).size.width * 0.15, - left: !projectViewModel.isArabic - ? 0 - : MediaQuery.of(context).size.width * 0.15), - ), - ], - ), - SizedBox( - height: 20, - ), - Column( - children: [ - Text( - "Driver", - style: TextStyle( - fontSize: 50, fontWeight: FontWeight.bold), - ), - Text( - "Delivery", - style: TextStyle(fontSize: 36, letterSpacing: 1), + child: AppScaffold( + isShowAppBar: false, + body: SingleChildScrollView( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FractionallySizedBox( + widthFactor: 0.80, + child: Column( + children: [ + SizedBox( + height: 40, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + child: Icon( + DriverApp.logo, + size: 70, + color: Theme.of(context).primaryColor, ), - Text( - "APP", + margin: EdgeInsets.only( + right: projectViewModel.isArabic + ? 0 + : MediaQuery.of(context).size.width * 0.15, + left: !projectViewModel.isArabic + ? 0 + : MediaQuery.of(context).size.width * 0.15), + ), + ], + ), + SizedBox( + height: 20, + ), + Column( + children: [ + Text( + "Driver", + style: TextStyle( + fontSize: 50, fontWeight: FontWeight.bold), + ), + Text( + "Delivery", + style: TextStyle(fontSize: 36, letterSpacing: 1), + ), + Text( + "APP", + style: TextStyle( + fontSize: 33, + letterSpacing: 33, + fontWeight: FontWeight.w400), + ), + ], + ), + SizedBox( + height: 30, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircleContainer( + onTap: () => projectViewModel.changeLanguage('en'), + child: Text( + TranslationBase.of(context).lanEnglish, style: TextStyle( - fontSize: 33, - letterSpacing: 33, - fontWeight: FontWeight.w400), + fontSize: 12, + color: projectViewModel.isArabic + ? Colors.black + : Colors.white), ), - ], - ), - SizedBox( - height: 30, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CircleContainer( - onTap: () => projectViewModel.changeLanguage('en'), + color: projectViewModel.isArabic + ? Colors.transparent + : Theme.of(context).primaryColor, + borderWidth: projectViewModel.isArabic ? 3 : 0, + borderColor: projectViewModel.isArabic + ? Theme.of(context).primaryColor + : Colors.transparent, + ), + SizedBox( + width: 20, + ), + CircleContainer( + onTap: () => + projectViewModel.changeLanguage('ar'), child: Text( - TranslationBase.of(context).lanEnglish, + TranslationBase.of(context).lanArabic, style: TextStyle( fontSize: 12, - color: projectViewModel.isArabic + color: !projectViewModel.isArabic ? Colors.black : Colors.white), ), - color: projectViewModel.isArabic + color: !projectViewModel.isArabic ? Colors.transparent : Theme.of(context).primaryColor, - borderWidth: projectViewModel.isArabic ? 3 : 0, - borderColor: projectViewModel.isArabic + borderWidth: !projectViewModel.isArabic ? 3 : 0, + borderColor: !projectViewModel.isArabic ? Theme.of(context).primaryColor - : Colors.transparent, + : Colors.transparent), + ], + ), + SizedBox( + height: 10, + ), + Form( + key: loginFormKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Expanded( + child: Text( + TranslationBase.of(context) + .enterCredentialsMsg, + style: TextStyle( + fontSize: 13, color: Colors.grey), + ), + ), + SizedBox( + height: 10, + ) + ], + ), ), SizedBox( - width: 20, + height: 10, ), - CircleContainer( - onTap: () => - projectViewModel.changeLanguage('ar'), - child: Text( - TranslationBase.of(context).lanArabic, + Container( + child: TextFields( + hintText: TranslationBase.of(context).enterId, + validator: (value) { + if (value.isEmpty) { + return TranslationBase.of(context) + .pleaseEnterYourID; + } + return null; + }, + onSaved: (value) { + loginRequest.userID = int.parse(value.trim()); + }, + ), + ), + SizedBox( + height: 20, + ), + Container( + child: TextFields( + borderRadiusValue: 6, + hintText: + TranslationBase.of(context).enterPassword, + validator: (value) { + if (value.isEmpty) { + return TranslationBase.of(context) + .pleaseEnterPassword; + } + return null; + }, + onSaved: (value) { + loginRequest.password = value; + }, + ), + ), + SizedBox( + height: 25, + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text( + TranslationBase.of(context).forgotPassword, style: TextStyle( - fontSize: 12, - color: !projectViewModel.isArabic - ? Colors.black - : Colors.white), + fontSize: 14, + color: Theme.of(context).primaryColor), ), - color: !projectViewModel.isArabic - ? Colors.transparent - : Theme.of(context).primaryColor, - borderWidth: !projectViewModel.isArabic ? 3 : 0, - borderColor: !projectViewModel.isArabic - ? Theme.of(context).primaryColor - : Colors.transparent), + ], + ), ], ), - SizedBox( - height: 10, + ), + ], + ), + ), + SizedBox( + height: 20, + ), + SizedBox( + height: 10, + ), + Container( + margin: EdgeInsets.all(10), + height: MediaQuery.of(context).size.height * 0.22, + child: Column( + children: [ + SecondaryButton( + label: TranslationBase.of(context).login, + onTap: () { + login(context); + }, + disabled: authenticationViewModel.isLoading, + loading: authenticationViewModel.isLoading, ), - Form( - key: loginFormKey, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Padding( - padding: - const EdgeInsets.symmetric(horizontal: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Expanded( - child: Text( - TranslationBase.of(context).enterCredentialsMsg, - style: TextStyle( - fontSize: 13, color: Colors.grey), - ), - ), - SizedBox( - height: 10, - ) - ], - ), - ), - SizedBox( - height: 10, - ), - Container( - child: TextFields( - hintText: TranslationBase.of(context).enterId, - validator: (value) { - if (value.isEmpty) { - return TranslationBase.of(context) - .pleaseEnterYourID; - } - return null; - }, - onSaved: (value) { - loginRequest.userID = int.parse(value.trim()); - }, - ), - ), - SizedBox( - height: 20, - ), - Container( - child: TextFields( - borderRadiusValue: 6, - hintText: - TranslationBase.of(context).enterPassword, - validator: (value) { - if (value.isEmpty) { - return TranslationBase.of(context) - .pleaseEnterPassword; - } - return null; - }, - onSaved: (value) { - loginRequest.password = value; - }, - ), - ), - SizedBox( - height: 25, - ), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Text( - TranslationBase.of(context).forgotPassword, - style: TextStyle( - fontSize: 14, - color: Theme.of(context).primaryColor), - ), - ], - ), - ], - ), + SizedBox( + height: 30, ), ], - ), - ), - SizedBox( - height: 20, - ), - SizedBox( - height: 10, - ),Container( - margin: EdgeInsets.all(10), - height: MediaQuery.of(context).size.height * 0.22, - child: Column( - children: [ - SecondaryButton( - label: TranslationBase.of(context).login, - onTap: () { - login(model, context); - }, - disabled: model.state == ViewState.BusyLocal, - loading: model.state == ViewState.BusyLocal, - ), - SizedBox( - height: 30, - ), - ], - )) - ], - ), + )) + ], ), ), - ), ), ); } - login(AuthenticationViewModel model, BuildContext context) async { + login(BuildContext context) async { if (loginFormKey.currentState.validate()) { loginFormKey.currentState.save(); - await model.login(loginRequest); - if (model.state == ViewState.ErrorLocal) { - Utils.showErrorToast(model.error); + await authenticationViewModel.login(loginRequest); + if (authenticationViewModel.isError) { + Utils.showErrorToast(authenticationViewModel.error); } else { Navigator.push( - context, MaterialPageRoute(builder: (context) => DashboardScreen())); + context, + MaterialPageRoute(builder: (context) => DashboardScreen())); } } } diff --git a/lib/pages/dashboard/dashboard_screen.dart b/lib/pages/dashboard/dashboard_screen.dart index 08cf7b1..d0f8c78 100644 --- a/lib/pages/dashboard/dashboard_screen.dart +++ b/lib/pages/dashboard/dashboard_screen.dart @@ -1,6 +1,8 @@ import 'package:barcode_scan/platform_wrapper.dart'; +import 'package:driverapp/config/size_config.dart'; import 'package:driverapp/core/enum/viewstate.dart'; import 'package:driverapp/core/model/scan_qr/scan_qr_request_model.dart'; +import 'package:driverapp/core/viewModels/authentication_view_model.dart'; import 'package:driverapp/core/viewModels/orders_view_model.dart'; import 'package:driverapp/pages/delivery/information_page.dart'; import 'package:driverapp/pages/orders/pending_orders_page.dart'; @@ -14,7 +16,8 @@ import 'package:driverapp/widgets/others/rounded_container.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; -import 'package:driverapp/config/size_config.dart'; +import 'package:provider/provider.dart'; + import '../base/base_view.dart'; class DashboardScreen extends StatefulWidget { @@ -23,537 +26,648 @@ class DashboardScreen extends StatefulWidget { } class _DashboardScreenState extends State { + bool isInit = false; + AuthenticationViewModel authenticationViewModel; + + @override + void didChangeDependencies() { + if (!isInit) { + authenticationViewModel = Provider.of(context); + setState(() { + isInit = !isInit; + }); + } + super.didChangeDependencies(); + } + @override Widget build(BuildContext context) { int orderId; + return BaseView( onModelReady: (model) => model.getPendingOrders(), builder: (BuildContext context, OrdersViewModel model, Widget child) => AppScaffold( + // baseViewModel: model, body: Container( - height: MediaQuery.of(context).size.height * .95, - child: ListView( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + height: MediaQuery.of(context).size.height * .95, + child: ListView( children: [ - Padding( - padding: EdgeInsets.all(16.0), - child: Column( - children: [ - SafeArea( + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: EdgeInsets.all(16.0), + child: Column( + children: [ + SafeArea( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + TranslationBase + .of(context) + .haveGreatDay, + style: TextStyle( + fontSize: 14.5, + color: Color(0xff636363), + fontWeight: FontWeight.w300), + ), + Padding( + padding: EdgeInsets.only(top: 4.5), + child: Text( +// 'Drive Name', + authenticationViewModel.user.userName, + style: TextStyle( + fontWeight: FontWeight.w400, + fontSize: 25.0), + ), + ), + ], + ), + ), + ], + ), + ), + Padding( + padding: EdgeInsets.all(16.0), + child: SafeArea( child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - TranslationBase.of(context).haveGreatDay, - style: TextStyle( - fontSize: 14.5, - color: Color(0xff636363), - fontWeight: FontWeight.w300), - ), - Padding( - padding: EdgeInsets.only(top: 4.5), - child: Text( - 'Drive Name', - //model.user.userName, - style: TextStyle( - fontWeight: FontWeight.w400, - fontSize: 25.0), + CircleAvatar( + radius: 25.5, + backgroundColor: Color(0xff30B7B9), + child: CircleAvatar( + backgroundColor: Color(0xff30B7B9), + maxRadius: 26.0, + child: Image.asset( + 'assets/images/driver.png', + fit: BoxFit.contain, + ), ), ), ], ), ), - ], - ), - ), - Padding( - padding: EdgeInsets.all(16.0), - child: SafeArea( - child: Column( - children: [ - CircleAvatar( - radius: 25.5, - backgroundColor: Color(0xff30B7B9), - child: CircleAvatar( - backgroundColor: Color(0xff30B7B9), - maxRadius: 26.0, - child: Image.asset( - 'assets/images/driver.png', - fit: BoxFit.contain, - ), - ), - ), - ], ), - ), + ], ), - ], - ), - Row( - children: [ - Expanded( - child: Column( - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.0), - child: Container( - height: MediaQuery.of(context).orientation == + Row( + children: [ + Expanded( + child: Column( + children: [ + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.0), + child: Container( + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context).size.height * 0.16 - : MediaQuery.of(context).size.height * 0.30, - width: MediaQuery.of(context).size.width * 0.44, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - gradient: LinearGradient(colors: [ - Color(0xff17AFB8), - Color(0xff49C1BC) - ]), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Padding( - padding: EdgeInsets.all(2.0), - child: Column( - mainAxisAlignment: + ? MediaQuery + .of(context) + .size + .height * 0.16 + : MediaQuery + .of(context) + .size + .height * 0.30, + width: MediaQuery + .of(context) + .size + .width * 0.44, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + gradient: LinearGradient(colors: [ + Color(0xff17AFB8), + Color(0xff49C1BC) + ]), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment + .spaceBetween, + children: [ + Expanded( + child: Padding( + padding: EdgeInsets.all(2.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Text( - TranslationBase.of(context).youHave, - style: TextStyle( - color: Colors.white, - fontSize: + children: [ + Text( + TranslationBase + .of(context) + .youHave, + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 2.2), - ), - Text( - '5', - style: TextStyle( - color: Colors.white, - fontSize: + ), + Text( + '5', + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 4.0), - ), - Text( - TranslationBase.of(context) - .undeliveredPackages, - style: TextStyle( - color: Colors.white, - fontSize: + ), + Text( + TranslationBase + .of(context) + .undeliveredPackages, + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 2.2), - ) - ], + ) + ], + ), + ), ), - ), - ), - Padding( - padding: EdgeInsets.only(right: 9.5), - child: Container( - width: 110, - height: 110, - decoration: BoxDecoration( - color: Colors.white10, - shape: BoxShape.circle), - child: Column( - mainAxisAlignment: + Padding( + padding: EdgeInsets.only(right: 9.5), + child: Container( + width: 110, + height: 110, + decoration: BoxDecoration( + color: Colors.white10, + shape: BoxShape.circle), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset( - 'assets/images/closed_box.png', - height: MediaQuery.of(context) - .orientation == + children: [ + Image.asset( + 'assets/images/closed_box.png', + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context) - .size - .height * + ? MediaQuery + .of(context) + .size + .height * 0.10 - : MediaQuery.of(context) - .size - .height * + : MediaQuery + .of(context) + .size + .height * 0.20, - width: MediaQuery.of(context) + width: MediaQuery + .of(context) .size .width * - 0.20, - scale: 0.9, - fit: BoxFit.contain, + 0.20, + scale: 0.9, + fit: BoxFit.contain, + ), + ], ), - ], + ), ), - ), + ], ), - ], - ), - ), - ) - ], - ), - ), - Expanded( - child: Column( - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.0), - child: Container( - height: MediaQuery.of(context).orientation == + ), + ) + ], + ), + ), + Expanded( + child: Column( + children: [ + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.0), + child: Container( + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context).size.height * 0.16 - : MediaQuery.of(context).size.height * 0.30, - width: MediaQuery.of(context).size.width * 0.45, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - gradient: LinearGradient(colors: [ - Color(0xff17AFB8), - Color(0xff49C1BC) - ]), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Padding( - padding: EdgeInsets.all(2.0), - child: Column( - mainAxisAlignment: + ? MediaQuery + .of(context) + .size + .height * 0.16 + : MediaQuery + .of(context) + .size + .height * 0.30, + width: MediaQuery + .of(context) + .size + .width * 0.45, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + gradient: LinearGradient(colors: [ + Color(0xff17AFB8), + Color(0xff49C1BC) + ]), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment + .spaceBetween, + children: [ + Expanded( + child: Padding( + padding: EdgeInsets.all(2.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Text( - TranslationBase.of(context).youHave, - style: TextStyle( - color: Colors.white, - fontSize: + children: [ + Text( + TranslationBase + .of(context) + .youHave, + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 2.2), - ), - Text( - '25', - style: TextStyle( - color: Colors.white, - fontSize: + ), + Text( + '25', + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 4.0), - ), - Text( - TranslationBase.of(context) - .deliveredPackages, - style: TextStyle( - color: Colors.white, - fontSize: + ), + Text( + TranslationBase + .of(context) + .deliveredPackages, + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 2.2), - ) - ], + ) + ], + ), + ), ), - ), - ), - Padding( - padding: EdgeInsets.only(right: 9.5), - child: Container( - width: 110, - height: 110, - decoration: BoxDecoration( - color: Colors.white10, - shape: BoxShape.circle), - child: Column( - mainAxisAlignment: + Padding( + padding: EdgeInsets.only(right: 9.5), + child: Container( + width: 110, + height: 110, + decoration: BoxDecoration( + color: Colors.white10, + shape: BoxShape.circle), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset( - 'assets/images/opend_box.png', - height: MediaQuery.of(context) - .orientation == + children: [ + Image.asset( + 'assets/images/opend_box.png', + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context) - .size - .height * + ? MediaQuery + .of(context) + .size + .height * 0.10 - : MediaQuery.of(context) - .size - .height * + : MediaQuery + .of(context) + .size + .height * 0.20, - width: MediaQuery.of(context) + width: MediaQuery + .of(context) .size .width * - 0.20, - scale: 0.9, - fit: BoxFit.contain, + 0.20, + scale: 0.9, + fit: BoxFit.contain, + ), + ], ), - ], + ), ), - ), + ], ), - ], - ), - ), - ) - ], - ), + ), + ) + ], + ), + ), + ], ), - ], - ), - Padding( - padding: EdgeInsets.symmetric(vertical: 16.0, horizontal: 15.0), - child: Row( - children: [ - Expanded( - child: InkWell( - child: Container( - height: MediaQuery.of(context).orientation == + Padding( + padding: EdgeInsets.symmetric( + vertical: 16.0, horizontal: 15.0), + child: Row( + children: [ + Expanded( + child: InkWell( + child: Container( + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context).size.height * 0.18 - : MediaQuery.of(context).size.height * 0.30, - width: MediaQuery.of(context).size.width * 0.50, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - gradient: LinearGradient( - colors: [ - Hexcolor("#45B7AE"), - Hexcolor("#119FA9") - ], - ), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, + ? MediaQuery + .of(context) + .size + .height * 0.18 + : MediaQuery + .of(context) + .size + .height * 0.30, + width: MediaQuery + .of(context) + .size + .width * 0.50, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + gradient: LinearGradient( + colors: [ + Hexcolor("#45B7AE"), + Hexcolor("#119FA9") + ], + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment + .spaceEvenly, children: [ - Image.asset( - 'assets/images/qr_code.png', - width: MediaQuery.of(context).size.width * - 0.26, - height: MediaQuery.of(context) - .orientation == + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset( + 'assets/images/qr_code.png', + width: MediaQuery + .of(context) + .size + .width * + 0.26, + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context).size.height * + ? MediaQuery + .of(context) + .size + .height * 0.14 - : MediaQuery.of(context).size.height * + : MediaQuery + .of(context) + .size + .height * 0.28, - fit: BoxFit.contain, - ) - ], - ), - Column( - mainAxisAlignment: + fit: BoxFit.contain, + ) + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - InkWell( - onTap: () { - _scanQrAndGetPatient(context, model); - }, - child: Padding( - padding: EdgeInsets.only(top: 8.0), - child: Text( - TranslationBase.of(context).scan, - style: TextStyle( - fontSize: + crossAxisAlignment: CrossAxisAlignment + .start, + children: [ + InkWell( + onTap: () { + _scanQrAndGetPatient(context, model); + }, + child: Padding( + padding: EdgeInsets.only(top: 8.0), + child: Text( + TranslationBase + .of(context) + .scan, + style: TextStyle( + fontSize: SizeConfig.textMultiplier * 6.0, - color: Colors.white, - fontWeight: FontWeight.w400, + color: Colors.white, + fontWeight: FontWeight.w400, + ), + ), ), ), - ), - ), - Padding( - padding: EdgeInsets.only(top: 0.0), - child: Text( - TranslationBase.of(context) - .toAddPackageToQue, - style: TextStyle( - fontSize: + Padding( + padding: EdgeInsets.only(top: 0.0), + child: Text( + TranslationBase + .of(context) + .toAddPackageToQue, + style: TextStyle( + fontSize: SizeConfig.textMultiplier * 3.0, - color: Colors.white, - letterSpacing: 0.2, - wordSpacing: 0.5, + color: Colors.white, + letterSpacing: 0.2, + wordSpacing: 0.5, + ), + ), ), - ), - ), + ], + ) ], - ) - ], - ), - ), - ), - ) - ], - ), - ), - NetworkBaseView( - baseViewModel: model, - child: Padding( - padding: - EdgeInsets.symmetric(horizontal: 20.0, vertical: 1.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Column( - children: [ - Text( - TranslationBase.of(context).nearestDropOffs, - style: TextStyle( - fontSize: 21.0, - fontWeight: FontWeight.w400, + ), ), ), - ], - ), - Column( - mainAxisAlignment: MainAxisAlignment.center, + ) + ], + ), + ), + NetworkBaseView( + baseViewModel: model, + child: Padding( + padding: + EdgeInsets.symmetric(horizontal: 20.0, vertical: 1.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - InkWell( - child: Row( - children: [ - Text( - TranslationBase.of(context).seeAll, - style: TextStyle( - fontSize: 14.5, color: Color(0xff42B6AD)), + Column( + children: [ + Text( + TranslationBase + .of(context) + .nearestDropOffs, + style: TextStyle( + fontSize: 21.0, + fontWeight: FontWeight.w400, ), - Icon( - Icons.arrow_forward_ios, - size: 15.0, - color: Color(0xff42B6AD), + ), + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + InkWell( + child: Row( + children: [ + Text( + TranslationBase + .of(context) + .seeAll, + style: TextStyle( + fontSize: 14.5, + color: Color(0xff42B6AD)), + ), + Icon( + Icons.arrow_forward_ios, + size: 15.0, + color: Color(0xff42B6AD), + ), + ], ), - ], - ), - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => OrdersListScreen()), - ), + onTap: () => + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + OrdersListScreen()), + ), + ), + ], ), ], ), - ], + ), ), - ), - ), - NetworkBaseView( - baseViewModel: model, - child: Expanded( - child: ListView.builder( - shrinkWrap: true, - scrollDirection: Axis.vertical, - itemCount: //model.orders == null ? 0 : model.orders.length, + NetworkBaseView( + baseViewModel: model, + child: Expanded( + child: ListView.builder( + shrinkWrap: true, + scrollDirection: Axis.vertical, + itemCount: //model.orders == null ? 0 : model.orders.length, 3, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: EdgeInsets.symmetric(horizontal: 12.2), - child: InkWell( - child: RoundedContainer( - raduis: 25.0, - height: MediaQuery.of(context).orientation == + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 12.2), + child: InkWell( + child: RoundedContainer( + raduis: 25.0, + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context).size.height * 0.109 - : MediaQuery.of(context).size.height * 0.209, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - flex: 1, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: + ? MediaQuery + .of(context) + .size + .height * 0.109 + : MediaQuery + .of(context) + .size + .height * 0.209, + child: Row( + mainAxisAlignment: MainAxisAlignment + .spaceBetween, + children: [ + Expanded( + flex: 1, + child: Column( + mainAxisAlignment: MainAxisAlignment + .start, + crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only( - left: 15.0, top: 14.0), - child: Image.asset( - 'assets/images/location.png', - height: MediaQuery.of(context) - .orientation == + children: [ + Padding( + padding: EdgeInsets.only( + left: 15.0, top: 14.0), + child: Image.asset( + 'assets/images/location.png', + height: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context) - .size - .height * + ? MediaQuery + .of(context) + .size + .height * 0.06 - : MediaQuery.of(context) - .size - .height * + : MediaQuery + .of(context) + .size + .height * 0.11, - width: MediaQuery.of(context) - .orientation == + width: MediaQuery + .of(context) + .orientation == Orientation.portrait - ? MediaQuery.of(context) - .size - .width * + ? MediaQuery + .of(context) + .size + .width * 0.05 - : MediaQuery.of(context) - .size - .width * + : MediaQuery + .of(context) + .size + .width * 0.09, - ), - ) - ], - ), - ), - if (model.orders.length != 0) - Expanded( - flex: 5, - child: Column( - crossAxisAlignment: + ), + ) + ], + ), + ), + if (model.orders.length != 0) + Expanded( + flex: 5, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only(top: 20.0), - child: Text( - model.orders[index].firstName + - ' ' + - model.orders[index].lastName, - style: TextStyle(fontSize: 18.0), - ), + children: [ + Padding( + padding: EdgeInsets.only( + top: 20.0), + child: Text( + model.orders[index].firstName + + ' ' + + model.orders[index] + .lastName, + style: TextStyle( + fontSize: 18.0), + ), + ), + Text( + model.orders[index].mobileNumber, + style: TextStyle( + color: Color(0xff30B7B9), + fontWeight: FontWeight.w600, + fontSize: 15.0, + ), + ), + ], ), - Text( - model.orders[index].mobileNumber, + ), + Padding( + padding: EdgeInsets.all(8.0), + child: CircleContainer( + child: Text( + model.orders[index] + .distanceInKilometers + .toString() + + ' K.m\naway', style: TextStyle( - color: Color(0xff30B7B9), - fontWeight: FontWeight.w600, - fontSize: 15.0, - ), + color: Color(0xff42B6AD), + fontWeight: FontWeight.w800, + fontStyle: FontStyle.normal), ), - ], - ), - ), - Padding( - padding: EdgeInsets.all(8.0), - child: CircleContainer( - child: Text( - model.orders[index].distanceInKilometers - .toString() + - ' K.m\naway', - style: TextStyle( - color: Color(0xff42B6AD), - fontWeight: FontWeight.w800, - fontStyle: FontStyle.normal), + ), ), - ), + ], ), - ], + ), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + InformationPage( + model.orders[index]))); + }, ), - ), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - InformationPage(model.orders[index]))); - }, - ), - ); - }, + ); + }, + ), + ), ), - ), + ], ), - ], + ), ), - ), - ), ); } diff --git a/lib/pages/delivery/information_page.dart b/lib/pages/delivery/information_page.dart index 99eae5b..cb8c352 100644 --- a/lib/pages/delivery/information_page.dart +++ b/lib/pages/delivery/information_page.dart @@ -1 +1 @@ -import 'package:driverapp/app-icons/driver_app_icons.dart'; import 'package:driverapp/core/enum/viewstate.dart'; import 'package:driverapp/core/model/orders/pending_orders_res_model.dart'; import 'package:driverapp/core/model/orders/update_order_status_request_model.dart'; import 'package:driverapp/core/viewModels/orders_view_model.dart'; import 'package:driverapp/pages/base/base_view.dart'; import 'package:driverapp/pages/delivery/delivery_confirmed_page.dart'; import 'package:driverapp/uitl/utils.dart'; import 'package:driverapp/widgets/bottom_sheet/action_sheet_button.dart'; import 'package:driverapp/widgets/bottom_sheet/custom_bottom_sheet.dart'; import 'package:driverapp/widgets/buttons/secondary_button.dart'; import 'package:driverapp/widgets/data_display/dialog/custom_dialog.dart'; import 'package:driverapp/widgets/data_display/text.dart'; import 'package:driverapp/widgets/delivery/customer_brief_card.dart'; import 'package:driverapp/widgets/delivery/delivery_action_button.dart'; import 'package:driverapp/widgets/delivery/package_content.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:maps_launcher/maps_launcher.dart'; import '../../uitl/translations_delegate_base.dart'; import '../../widgets/others/app_scaffold_widget.dart'; class InformationPage extends StatelessWidget { final PendingOrdersRes item; int orderStatus; InformationPage(this.item); @override Widget build(BuildContext context) { return BaseView( builder: (_, model, w) => AppScaffold( isShowAppBar: true, appBarColor: Theme.of(context).primaryColor, arrowColor: Colors.white, titleColor: Colors.white, appBarTitle: TranslationBase.of(context).deliveryInfo, body: Container( color: Theme.of(context).primaryColor, child: Container( color: Theme.of(context).primaryColor, child: ListView( children: [ Column( children: [ Stack( children: [ Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.width, ), Container( width: MediaQuery.of(context).size.width * 1, height: MediaQuery.of(context).size.width * 1.5, margin: EdgeInsets.only( top: MediaQuery.of(context).size.width * 0.23, ), decoration: BoxDecoration( color: Theme.of(context).scaffoldBackgroundColor, borderRadius: BorderRadius.only( topLeft: Radius.circular(45), topRight: Radius.circular(45)), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( height: MediaQuery.of(context).size.width * 0.53, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ DeliveryInfoButton( btnColor: Color(0xffED1C24), btnIcon: Icon( Icons.near_me, size: 30, color: Colors.white, ), btnName: TranslationBase.of(context).location, btnFunction: () { MapsLauncher.launchCoordinates( item.latitude, item.longitude); },), DeliveryInfoButton( btnColor: Color(0xFF61B260), btnIcon: Icon( Icons.whatshot, size: 30, color: Colors.white, ), btnName: 'Whatsapp', btnFunction: () {}, ), DeliveryInfoButton( btnColor: Color(0xFFFCB657), btnIcon: Icon( Icons.mail_outline, size: 30, color: Colors.white, ), btnName: TranslationBase.of(context).sms, btnFunction: () {}, ), DeliveryInfoButton( btnColor: Theme.of(context).primaryColor, btnIcon: Icon( Icons.phone, size: 30, color: Colors.white, ), btnName: TranslationBase.of(context).call, btnFunction: () => launch("tel://" + item.mobileNumber), ), ], ), SizedBox( height: MediaQuery.of(context).size.width * 0.1, ), Container( margin: EdgeInsets.only( left: MediaQuery.of(context).size.width * 0.05, right: MediaQuery.of(context).size.width * 0.05, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.only(left: 8), child: Text( TranslationBase.of(context) .packageContent, style: TextStyle( fontWeight: FontWeight.w900, fontSize: 20), ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.05, ), Padding( padding: const EdgeInsets.only(left: 10), child: Column( children: List.generate( item.itemsQuantitiesList.length, (index) { return packageContent( packageName: item .itemsQuantitiesList[index] .itemName .toString(), packageCount: item .itemsQuantitiesList[index] .quantity .toString(), ); }), ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.01, ), ], ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.1, ), Container( margin: EdgeInsets.all(10), child: SecondaryButton( label: TranslationBase.of(context).clientReached, onTap: () { model.showBottomSheet(); }, ), ), ], ), ), CustomerBriefCard( itemId: item.patientID, customerFirstName: item.firstName, customerLastName: item.lastName, mobileNo: item.mobileNumber, totalPayment: item.amount, deliveryTime: item.orderCreatedOn, longitude: item.longitude, latitude: item.latitude, ),], ), ], ), ], ), ), ), bottomSheet: !model.isBottomSheetAppear ? Container( width: 0, height: 0, ) : CustomBottomSheet(children: [ SizedBox( height: 10, ), Center( child: Texts( TranslationBase.of(context).selectAction, color: Colors.black, fontSize: 22, ), ), SizedBox( height: 10, ), FractionallySizedBox( widthFactor: 0.9, child: Column( children: [ SizedBox( height: 3, child: Container( color: Hexcolor("#D5D5D5"), ), ), SizedBox( height: 15, ), ActionSheetButton( label: TranslationBase .of(context) .delivered, icon: DriverApp.deliverd_icon, onTap: () { selectAction(context, 3, model); }, ), SizedBox( height: 15 ), ActionSheetButton( label: TranslationBase .of(context) .deliveredAccepted, icon: DriverApp.not_available, onTap: () { selectAction(context, 4, model); }, ), SizedBox( height: 15 ), ActionSheetButton( label: TranslationBase .of(context) .deliveredRejected, icon: DriverApp.rejected_icon, onTap: () { selectAction(context, 5, model); }, ), SizedBox( height: 15 ), ActionSheetButton( label: TranslationBase .of(context) .canceled, icon: DriverApp.not_reachable_icon, onTap: () { selectAction(context, 6, model); }, ), SizedBox( height: 15 ), ], )), ]), ), ); } selectAction(BuildContext context, orderStatus, OrdersViewModel model) { String orderStatusText; this.orderStatus = orderStatus; switch (orderStatus) { case 3: orderStatusText = TranslationBase .of(context) .delivered; break; case 4: orderStatusText = TranslationBase .of(context) .deliveredAccepted; break; case 5: orderStatusText = TranslationBase .of(context) .deliveredRejected; break; case 6: orderStatusText = TranslationBase .of(context) .canceled; break; } showDialog( context: context, builder: (BuildContext context) { return CustomDialog( orderStatusText: orderStatusText, callService: () { updateOrderStatus(context, model); }, model: model,); }); } updateOrderStatus(BuildContext context, OrdersViewModel model) async { UpdateOrderStatusRequestModel updateOrderStatusRequestModel = UpdateOrderStatusRequestModel(deliveryOrderID: item.orderID, deliveryOrderStatus: orderStatus, rejectionReason: "NO Reason", cancleReason: ""); await model.updateOrderStatus(updateOrderStatusRequestModel); if (model.state == ViewState.ErrorLocal) { Utils.showErrorToast(model.error); Navigator.of(context).pop(); model.hideBottomSheet(); } else { Navigator.of(context).pop(); model.hideBottomSheet(); Navigator.push( context, MaterialPageRoute( builder: (context) => DeliveryConfirmedPage(item), ), ); } } } \ No newline at end of file +import 'package:driverapp/app-icons/driver_app_icons.dart'; import 'package:driverapp/core/enum/viewstate.dart'; import 'package:driverapp/core/model/orders/pending_orders_res_model.dart'; import 'package:driverapp/core/model/orders/update_order_status_request_model.dart'; import 'package:driverapp/core/viewModels/orders_view_model.dart'; import 'package:driverapp/pages/base/base_view.dart'; import 'package:driverapp/pages/delivery/delivery_confirmed_page.dart'; import 'package:driverapp/uitl/utils.dart'; import 'package:driverapp/widgets/bottom_sheet/action_sheet_button.dart'; import 'package:driverapp/widgets/bottom_sheet/custom_bottom_sheet.dart'; import 'package:driverapp/widgets/buttons/secondary_button.dart'; import 'package:driverapp/widgets/data_display/dialog/custom_dialog.dart'; import 'package:driverapp/widgets/data_display/text.dart'; import 'package:driverapp/widgets/delivery/customer_brief_card.dart'; import 'package:driverapp/widgets/delivery/delivery_action_button.dart'; import 'package:driverapp/widgets/delivery/package_content.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:maps_launcher/maps_launcher.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../uitl/translations_delegate_base.dart'; import '../../widgets/others/app_scaffold_widget.dart'; class InformationPage extends StatelessWidget { final PendingOrdersRes item; int orderStatus; InformationPage(this.item); @override Widget build(BuildContext context) { return BaseView( builder: (_, model, w) => AppScaffold( isShowAppBar: true, appBarColor: Theme.of(context).primaryColor, arrowColor: Colors.white, titleColor: Colors.white, appBarTitle: TranslationBase.of(context).deliveryInfo, body: Container( color: Theme.of(context).primaryColor, child: Container( color: Theme.of(context).primaryColor, child: ListView( children: [ Column( children: [ Stack( children: [ Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.width, ), Container( width: MediaQuery.of(context).size.width * 1, height: MediaQuery.of(context).size.width * 1.5, margin: EdgeInsets.only( top: MediaQuery.of(context).size.width * 0.23, ), decoration: BoxDecoration( color: Theme.of(context).scaffoldBackgroundColor, borderRadius: BorderRadius.only( topLeft: Radius.circular(45), topRight: Radius.circular(45)), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( height: MediaQuery.of(context).size.width * 0.53, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ DeliveryInfoButton( btnColor: Color(0xffED1C24), btnIcon: Icon( Icons.near_me, size: 30, color: Colors.white, ), btnName: TranslationBase.of(context).location, btnFunction: () { MapsLauncher.launchCoordinates( item.latitude, item.longitude); },), DeliveryInfoButton( btnColor: Color(0xFF61B260), btnIcon: Icon( Icons.whatshot, size: 30, color: Colors.white, ), btnName: 'Whatsapp', btnFunction: () {}, ), DeliveryInfoButton( btnColor: Color(0xFFFCB657), btnIcon: Icon( Icons.mail_outline, size: 30, color: Colors.white, ), btnName: TranslationBase.of(context).sms, btnFunction: () {}, ), DeliveryInfoButton( btnColor: Theme.of(context).primaryColor, btnIcon: Icon( Icons.phone, size: 30, color: Colors.white, ), btnName: TranslationBase.of(context).call, btnFunction: () => launch("tel://" + item.mobileNumber), ), ], ), SizedBox( height: MediaQuery.of(context).size.width * 0.1, ), Container( margin: EdgeInsets.only( left: MediaQuery.of(context).size.width * 0.05, right: MediaQuery.of(context).size.width * 0.05, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.only(left: 8), child: Text( TranslationBase.of(context) .packageContent, style: TextStyle( fontWeight: FontWeight.w900, fontSize: 20), ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.05, ), Padding( padding: const EdgeInsets.only(left: 10), child: Column( children: List.generate( item.itemsQuantitiesList != null ? item .itemsQuantitiesList.length : 0, (index) { return packageContent( packageName: item .itemsQuantitiesList[index] .itemName .toString(), packageCount: item .itemsQuantitiesList[index] .quantity .toString(), ); }), ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.01, ), ], ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.1, ), Container( margin: EdgeInsets.all(10), child: SecondaryButton( label: TranslationBase .of(context) .clientReached, onTap: () { model.showBottomSheet(); }, ), ), ], ), ), CustomerBriefCard( itemId: item.patientID, customerFirstName: item.firstName, customerLastName: item.lastName, mobileNo: item.mobileNumber, totalPayment: item.amount, deliveryTime: item.orderCreatedOn, longitude: item.longitude, latitude: item.latitude, ), ], ), ], ), ], ), ), ), bottomSheet: !model.isBottomSheetAppear ? Container( width: 0, height: 0, ) : CustomBottomSheet(children: [ SizedBox( height: 10, ), Center( child: Texts( TranslationBase.of(context).selectAction, color: Colors.black, fontSize: 22, ), ), SizedBox( height: 10, ), FractionallySizedBox( widthFactor: MediaQuery .of(context) .orientation == Orientation.portrait ? 0.9 : 0.98, child: Container( height: MediaQuery .of(context) .size .height * 0.43, width: double.infinity, child: ListView( children: [ Column( children: [ SizedBox( height: 3, child: Container( color: Hexcolor("#D5D5D5"), ), ), SizedBox( height: 15, ), ActionSheetButton( label: TranslationBase .of(context) .delivered, icon: DriverApp.deliverd_icon, onTap: () { selectAction(context, 3, model); }, ), SizedBox(height: 15), ActionSheetButton( label: TranslationBase .of(context) .deliveredAccepted, icon: DriverApp.not_available, onTap: () { selectAction(context, 4, model); }, ), SizedBox(height: 15), ActionSheetButton( label: TranslationBase .of(context) .deliveredRejected, icon: DriverApp.rejected_icon, onTap: () { selectAction(context, 5, model); }, ), SizedBox(height: 15), ActionSheetButton( label: TranslationBase .of(context) .canceled, icon: DriverApp.not_reachable_icon, onTap: () { selectAction(context, 6, model); }, ), SizedBox(height: 15), ], ), ], ), )), ]), ), ); } selectAction(BuildContext context, orderStatus, OrdersViewModel model) { String orderStatusText; this.orderStatus = orderStatus; switch (orderStatus) { case 3: orderStatusText = TranslationBase .of(context) .delivered; break; case 4: orderStatusText = TranslationBase .of(context) .deliveredAccepted; break; case 5: orderStatusText = TranslationBase .of(context) .deliveredRejected; break; case 6: orderStatusText = TranslationBase .of(context) .canceled; break; } showDialog( context: context, builder: (BuildContext context) { return CustomDialog( orderStatusText: orderStatusText, callService: () { updateOrderStatus(context, model); }, model: model,); }); } updateOrderStatus(BuildContext context, OrdersViewModel model) async { UpdateOrderStatusRequestModel updateOrderStatusRequestModel = UpdateOrderStatusRequestModel(deliveryOrderID: item.orderID, deliveryOrderStatus: orderStatus, rejectionReason: "NO Reason", cancleReason: ""); await model.updateOrderStatus(updateOrderStatusRequestModel); if (model.state == ViewState.ErrorLocal) { Utils.showErrorToast(model.error); Navigator.of(context).pop(); model.hideBottomSheet(); } else { Navigator.of(context).pop(); model.hideBottomSheet(); Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => DeliveryConfirmedPage(item), ), ); } } } \ No newline at end of file diff --git a/lib/root_page.dart b/lib/root_page.dart index 3e1dbff..329d0f6 100644 --- a/lib/root_page.dart +++ b/lib/root_page.dart @@ -1,34 +1,35 @@ import 'package:driverapp/pages/authentication/login_page.dart'; -import 'package:driverapp/pages/base/base_view.dart'; -import 'package:driverapp/pages/landing/landing_page.dart'; -import 'package:driverapp/widgets/others/app_scaffold_widget.dart'; +import 'package:driverapp/pages/dashboard/dashboard_screen.dart'; +import 'package:driverapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:driverapp/pages/dashboard/dashboard_screen.dart'; +import 'package:provider/provider.dart'; import 'core/viewModels/authentication_view_model.dart'; class RootPage extends StatelessWidget { @override Widget build(BuildContext context) { - Widget buildRoot(APP_STATUS status) { + AuthenticationViewModel authenticationViewModel = Provider.of(context); + APP_STATUS status = authenticationViewModel.status; + Widget buildRoot() { switch (status) { case APP_STATUS.UNAUTHENTICATED: - return LoginPage (); + return LoginPage(); break; case APP_STATUS.AUTHENTICATED: return DashboardScreen(); break; + case APP_STATUS.LOADING: + return Center(child: AppCircularProgressIndicator()); + break; } } return AnimatedSwitcher( duration: Duration(microseconds: 350), - child: BaseView( - builder: (_, model, widget) => AppScaffold( - baseViewModel: model, - body: buildRoot((model.status)), - ), + child: Scaffold( + body: buildRoot(), ), ); }