diff --git a/lib/core/model/authentication/authenticated_user.dart b/lib/core/model/authentication/authenticated_user.dart index 0329bd5..a055f41 100644 --- a/lib/core/model/authentication/authenticated_user.dart +++ b/lib/core/model/authentication/authenticated_user.dart @@ -8,19 +8,19 @@ class AuthenticatedUser { bool active; String createdOn; int createdBy; - Null editedOn; - Null editedBy; + dynamic editedOn; + dynamic editedBy; String mobileNumber; int realRoleID; AuthenticatedUser( {this.iD, - this.userID, - this.password, - this.userName, - this.roleID, - this.name, - this.active, + this.userID, + this.password, + this.userName, + this.roleID, + this.name, + this.active, this.createdOn, this.createdBy, this.editedOn, diff --git a/lib/core/service/orders_service.dart b/lib/core/service/orders_service.dart index 3320ab6..d837ebb 100644 --- a/lib/core/service/orders_service.dart +++ b/lib/core/service/orders_service.dart @@ -22,7 +22,8 @@ class OrdersService extends BaseService { List get nextOrdersList => _nextOrdersList; bool isOrderInserted; bool isOrderStatusUpdated; - + bool isGetPendingOrdersServices = false; + bool isGetDeliveredOrdersServices = false; DeliverdOrderModel _requestGetDeliveredOrders = DeliverdOrderModel( searchKey: "", pageSize: 0, @@ -33,7 +34,9 @@ class OrdersService extends BaseService { Future getPendingOrders() async { LocationData loc = await Utils.getLocation(); - + if (user != null) { + isGetPendingOrdersServices = true; + } if (loc != null) { PendingOrders _requestGetPendingOrders = PendingOrders( searchKey: "", @@ -127,6 +130,9 @@ class OrdersService extends BaseService { latitude: loc.latitude.toString(), longitude: loc.longitude.toString(), ); + if (user != null) { + isGetDeliveredOrdersServices = true; + } if (loc != null) { hasError = false; try { diff --git a/lib/core/viewModels/orders_view_model.dart b/lib/core/viewModels/orders_view_model.dart index 878004c..eec100a 100644 --- a/lib/core/viewModels/orders_view_model.dart +++ b/lib/core/viewModels/orders_view_model.dart @@ -20,17 +20,22 @@ class OrdersViewModel extends BaseViewModel { List get nextOrdersList => _ordersService.nextOrdersList; bool isBottomSheetAppear = false; + bool get isGetPendingOrdersServices => + _ordersService.isGetPendingOrdersServices; + + bool get isGetDeliveredOrdersServices => + _ordersService.isGetDeliveredOrdersServices; + Future getPendingOrders() async { setState(ViewState.Busy); await _ordersService.getPendingOrders(); if (_ordersService.hasError) { error = _ordersService.error; setState(ViewState.Error); - } else - setState(ViewState.Idle); + } } - Future getDeliverdOrders() async { + Future getDeliveredOrders() async { setState(ViewState.Busy); await _ordersService.getDeliveredList(); if (_ordersService.hasError) { diff --git a/lib/pages/authentication/login_page.dart b/lib/pages/authentication/login_page.dart index 69c4075..c9ed541 100644 --- a/lib/pages/authentication/login_page.dart +++ b/lib/pages/authentication/login_page.dart @@ -19,21 +19,21 @@ class LoginPage extends StatelessWidget { ProjectViewModel projectViewModel; AuthenticationViewModel authenticationViewModel; + login() async { + if (loginFormKey.currentState.validate()) { + loginFormKey.currentState.save(); + await authenticationViewModel.login(loginRequest); + if (authenticationViewModel.isError) { + Utils.showErrorToast(authenticationViewModel.error); + } + } + } + @override 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( @@ -44,59 +44,59 @@ class LoginPage extends StatelessWidget { 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), - ), - Text( - "APP", - style: TextStyle( - fontSize: 33, - letterSpacing: 33, - fontWeight: FontWeight.w400), + 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, ), - ], - ), - SizedBox( - height: 30, - ), + 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, @@ -143,47 +143,48 @@ class LoginPage extends StatelessWidget { // : 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, + ), + 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, + ) + ], ), - SizedBox( - height: 10, - ), - Container( - child: TextFields( - hintText: TranslationBase.of(context).enterId, - validator: (value) { - if (value.isEmpty) { - return TranslationBase.of(context) - .pleaseEnterYourID; - } - return null; - }, + ), + SizedBox( + height: 10, + ), + Container( + child: TextFields( + hintText: TranslationBase.of(context).enterId, + keyboardType: TextInputType.number, + validator: (value) { + if (value.isEmpty) { + return TranslationBase.of(context) + .pleaseEnterYourID; + } + return null; + }, onSaved: (value) { loginRequest.userID = int.parse(value.trim()); }, @@ -196,7 +197,7 @@ class LoginPage extends StatelessWidget { child: TextFields( borderRadiusValue: 6, hintText: - TranslationBase.of(context).enterPassword, + TranslationBase.of(context).enterPassword, validator: (value) { if (value.isEmpty) { return TranslationBase.of(context) @@ -228,15 +229,15 @@ class LoginPage extends StatelessWidget { ], ), ), - ], - ), - ), - SizedBox( - height: 20, - ), - SizedBox( - height: 10, + ], ), + ), + SizedBox( + height: 20, + ), + SizedBox( + height: 10, + ), Container( margin: EdgeInsets.all(10), diff --git a/lib/pages/dashboard/dashboard_screen.dart b/lib/pages/dashboard/dashboard_screen.dart index 343aeac..581d1cf 100644 --- a/lib/pages/dashboard/dashboard_screen.dart +++ b/lib/pages/dashboard/dashboard_screen.dart @@ -52,9 +52,18 @@ class _DashboardScreenState extends State { Widget build(BuildContext context) { int orderId; return BaseView( - onModelReady: (model) => model.getPendingOrders(), + onModelReady: (model) async { + if (!model.isGetPendingOrdersServices) { + await model.getPendingOrders(); + } + + if (!model.isGetDeliveredOrdersServices) { + await model.getDeliveredOrders(); + } + }, builder: (BuildContext context, OrdersViewModel model, Widget child) => AppScaffold( + baseViewModel: model, body: SingleChildScrollView( child: Container( height: MediaQuery.of(context).orientation == Orientation.landscape @@ -149,93 +158,105 @@ class _DashboardScreenState extends State { borderRadius: BorderRadius.circular(15.0), gradient: LINEAR_GRADIENT, ), - 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: MediaQuery.of(context) - .orientation == - Orientation.landscape - ? SizeConfig.textMultiplier * - 2.2 - : SizeConfig.textMultiplier * - 1.3, - ), - ), - Text( - '5', - style: TextStyle( + child: InkWell( + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + OrdersListScreen())), + 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: - SizeConfig.textMultiplier * - 3.0), - ), - Text( - TranslationBase.of(context) - .undeliveredPackages, - style: TextStyle( - color: Colors.white, - fontSize: MediaQuery.of(context) - .orientation == - Orientation.landscape - ? SizeConfig.textMultiplier * - 2.2 - : SizeConfig.textMultiplier * - 1.3, + fontSize: MediaQuery.of(context) + .orientation == + Orientation.landscape + ? SizeConfig + .textMultiplier * + 2.2 + : SizeConfig + .textMultiplier * + 1.3, + ), + ), + Text( + model.orders.length.toString(), + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig + .textMultiplier * + 3.0), ), - ) - ], + Text( + TranslationBase.of(context) + .undeliveredPackages, + style: TextStyle( + color: Colors.white, + fontSize: MediaQuery.of(context) + .orientation == + Orientation.landscape + ? SizeConfig + .textMultiplier * + 2.2 + : SizeConfig + .textMultiplier * + 1.3, + ), + ) + ], + ), ), ), - ), - Padding( - padding: EdgeInsets.only(right: 9.5), - child: Container( - width: 100, - height: 100, - 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 == - Orientation.portrait - ? MediaQuery.of(context) - .size - .height * - 0.09 - : MediaQuery.of(context) - .size - .height * - 0.20, - width: MediaQuery.of(context) - .size - .width * - 0.20, - scale: 0.9, - fit: BoxFit.contain, - ), - ], + Padding( + padding: EdgeInsets.only(right: 9.5), + child: Container( + width: 100, + height: 100, + 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 == + Orientation.portrait + ? MediaQuery.of(context) + .size + .height * + 0.09 + : MediaQuery.of(context) + .size + .height * + 0.20, + width: MediaQuery.of(context) + .size + .width * + 0.20, + scale: 0.9, + fit: BoxFit.contain, + ), + ], + ), ), ), - ), - ], + ], + ), ), ), ) @@ -291,7 +312,8 @@ class _DashboardScreenState extends State { ), ), Text( - '3', + model.deliverdOrders.length + .toString(), style: TextStyle( color: Colors.white, fontSize: SizeConfig @@ -511,7 +533,9 @@ class _DashboardScreenState extends State { scrollDirection: Axis.vertical, itemCount: model.orders == null ? 0 - : model.orders.length < 3 ? model.orders.length : 3, + : model.orders.length < 3 + ? model.orders.length + : 3, itemBuilder: (BuildContext context, int index) { return Padding( padding: EdgeInsets.symmetric(horizontal: 0.2), diff --git a/lib/pages/orders/deliverd_orders_page.dart b/lib/pages/orders/deliverd_orders_page.dart index 6eaa83c..9f21fa6 100644 --- a/lib/pages/orders/deliverd_orders_page.dart +++ b/lib/pages/orders/deliverd_orders_page.dart @@ -17,7 +17,7 @@ class _DeliverdOrdersPageState extends State { @override Widget build(BuildContext context) { return BaseView( - onModelReady: (model) => model.getDeliverdOrders(), + // onModelReady: (model) => model.getDeliveredOrders(), builder: (BuildContext context, OrdersViewModel model, Widget child) => AppScaffold( isShowAppBar: true, diff --git a/lib/pages/splash_screen_page.dart b/lib/pages/splash_screen_page.dart index f094e0c..b9c6f11 100644 --- a/lib/pages/splash_screen_page.dart +++ b/lib/pages/splash_screen_page.dart @@ -1,21 +1,33 @@ -import 'dart:async'; - import 'package:driverapp/app-icons/driver_app_icons.dart'; +import 'package:driverapp/core/viewModels/orders_view_model.dart'; import 'package:driverapp/core/viewModels/project_view_model.dart'; import 'package:driverapp/root_page.dart'; import 'package:driverapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import '../locator.dart'; + class SplashScreenPage extends StatefulWidget { @override _SplashScreenPageState createState() => _SplashScreenPageState(); } class _SplashScreenPageState extends State { + OrdersViewModel _ordersViewModel = locator(); + + // AuthenticationService _authenticationService = + // locator(); + startTime() async { - var _duration = new Duration(seconds: 5); - return new Timer(_duration, navigationPage); + // if (_authenticationService.isLogin) { + await _ordersViewModel.getPendingOrders(); + await _ordersViewModel.getDeliveredOrders(); + // } + + navigationPage(); + // var _duration = new Duration(seconds: 5); + // return new Timer(_duration, navigationPage); } @override @@ -24,6 +36,8 @@ class _SplashScreenPageState extends State { startTime(); } + // + @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); @@ -54,7 +68,7 @@ class _SplashScreenPageState extends State { children: [ SizedBox( height: MediaQuery.of(context).orientation == - Orientation.portrait + Orientation.portrait ? 200 : 50, ), @@ -65,7 +79,7 @@ class _SplashScreenPageState extends State { child: Icon( DriverApp.logo, size: MediaQuery.of(context).orientation == - Orientation.portrait + Orientation.portrait ? 120 : 70, color: Colors.white, @@ -85,7 +99,7 @@ class _SplashScreenPageState extends State { ), SizedBox( height: MediaQuery.of(context).orientation == - Orientation.portrait + Orientation.portrait ? 20 : 15, ), @@ -95,7 +109,7 @@ class _SplashScreenPageState extends State { "Driver", style: TextStyle( fontSize: MediaQuery.of(context).orientation == - Orientation.portrait + Orientation.portrait ? 70 : 35, fontWeight: FontWeight.bold, @@ -105,7 +119,7 @@ class _SplashScreenPageState extends State { "Delivery", style: TextStyle( fontSize: MediaQuery.of(context).orientation == - Orientation.portrait + Orientation.portrait ? 50 : 25, letterSpacing: 1, @@ -114,15 +128,19 @@ class _SplashScreenPageState extends State { Text( "APP", style: TextStyle( - fontSize: MediaQuery.of(context).orientation == - Orientation.portrait + fontSize: MediaQuery + .of(context) + .orientation == + Orientation.portrait ? 53 : 21, letterSpacing: - MediaQuery.of(context).orientation == - Orientation.portrait - ? 53 - : 27, + MediaQuery + .of(context) + .orientation == + Orientation.portrait + ? 53 + : 27, color: Colors.white, fontWeight: FontWeight.w400), ), @@ -130,7 +148,7 @@ class _SplashScreenPageState extends State { ), SizedBox( height: MediaQuery.of(context).orientation == - Orientation.portrait + Orientation.portrait ? 100 : 50, ) @@ -162,7 +180,7 @@ class _SplashScreenPageState extends State { ), SizedBox( height: MediaQuery.of(context).orientation == - Orientation.portrait + Orientation.portrait ? 10 : 5, ) diff --git a/lib/widgets/others/network_base_view.dart b/lib/widgets/others/network_base_view.dart index 42bfde6..fe409bc 100644 --- a/lib/widgets/others/network_base_view.dart +++ b/lib/widgets/others/network_base_view.dart @@ -25,7 +25,7 @@ class NetworkBaseView extends StatelessWidget { return child; break; case ViewState.Busy: - return Expanded(child: AppCircularProgressIndicator()); + return AppCircularProgressIndicator(); break; case ViewState.Error: return Center(