diff --git a/lib/core/service/orders_service.dart b/lib/core/service/orders_service.dart index 301507a..3320ab6 100644 --- a/lib/core/service/orders_service.dart +++ b/lib/core/service/orders_service.dart @@ -13,15 +13,17 @@ import 'package:location/location.dart'; class OrdersService extends BaseService { List _orders = List(); List _nextOrdersList = List(); - List _deliverdOrderList = List(); + List _deliveredOrderList = List(); + List get orders => _orders; - List get deliverdOrderList => _deliverdOrderList; + + List get deliveredOrderList => _deliveredOrderList; List get nextOrdersList => _nextOrdersList; bool isOrderInserted; bool isOrderStatusUpdated; - DeliverdOrderModel _requestGetDeliverdOrders = DeliverdOrderModel( + DeliverdOrderModel _requestGetDeliveredOrders = DeliverdOrderModel( searchKey: "", pageSize: 0, pageIndex: 0, @@ -30,7 +32,6 @@ class OrdersService extends BaseService { ); Future getPendingOrders() async { - // if (await Utils.isLocationPermissionGranted()) { LocationData loc = await Utils.getLocation(); if (loc != null) { @@ -117,7 +118,7 @@ class OrdersService extends BaseService { } } - Future getDeliverdList() async { + Future getDeliveredList() async { LocationData loc = await Utils.getLocation(); PendingOrders _requestGetPendingOrders = PendingOrders( searchKey: "", @@ -126,23 +127,26 @@ class OrdersService extends BaseService { latitude: loc.latitude.toString(), longitude: loc.longitude.toString(), ); - hasError = false; - try { - await baseAppClient.post(GET_ALL_DELIVERD_ORDER, - onSuccess: (dynamic response, int statusCode) { - _deliverdOrderList.clear(); - response['PatientER_Delivery_GetAllDeliverdOrderList'].forEach((order) { - _deliverdOrderList.add(DeliverdOrderResModel.fromJson(order)); - }); - }, onFailure: (String error, int statusCode) { + if (loc != null) { + hasError = false; + try { + await baseAppClient.post(GET_ALL_DELIVERD_ORDER, + onSuccess: (dynamic response, int statusCode) { + _deliveredOrderList.clear(); + response['PatientER_Delivery_GetAllDeliverdOrderList'] + .forEach((order) { + _deliveredOrderList.add(DeliverdOrderResModel.fromJson(order)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: _requestGetPendingOrders.toJson()); + } catch (e) { hasError = true; super.error = error; - }, body: _requestGetPendingOrders.toJson()); - } catch (e) { - hasError = true; - super.error = error; - throw e; + throw e; + } } } } diff --git a/lib/core/viewModels/orders_view_model.dart b/lib/core/viewModels/orders_view_model.dart index 028656e..878004c 100644 --- a/lib/core/viewModels/orders_view_model.dart +++ b/lib/core/viewModels/orders_view_model.dart @@ -1,11 +1,11 @@ import 'package:driverapp/core/enum/viewstate.dart'; -import 'package:driverapp/core/model/orders/deliverd_order_req_model.dart'; +import 'package:driverapp/core/model/orders/deliverd_order_res_model.dart'; import 'package:driverapp/core/model/orders/next_order_request_model.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/model/scan_qr/scan_qr_request_model.dart'; import 'package:driverapp/core/service/orders_service.dart'; -import 'package:driverapp/core/model/orders/deliverd_order_res_model.dart'; + import '../../locator.dart'; import 'base_view_model.dart'; @@ -15,7 +15,7 @@ class OrdersViewModel extends BaseViewModel { List get orders => _ordersService.orders; List get deliverdOrders => - _ordersService.deliverdOrderList; + _ordersService.deliveredOrderList; List get nextOrdersList => _ordersService.nextOrdersList; bool isBottomSheetAppear = false; @@ -32,7 +32,7 @@ class OrdersViewModel extends BaseViewModel { Future getDeliverdOrders() async { setState(ViewState.Busy); - await _ordersService.getDeliverdList(); + await _ordersService.getDeliveredList(); if (_ordersService.hasError) { error = _ordersService.error; setState(ViewState.Error); diff --git a/lib/pages/dashboard/dashboard_screen.dart b/lib/pages/dashboard/dashboard_screen.dart index 9fc30e4..6b9289a 100644 --- a/lib/pages/dashboard/dashboard_screen.dart +++ b/lib/pages/dashboard/dashboard_screen.dart @@ -45,7 +45,7 @@ class _DashboardScreenState extends State { void initState() { super.initState(); // TODO return it - // Utils.getLocationPermission(); + Utils.getLocation(); } @override diff --git a/lib/pages/setting/request_permission_page.dart b/lib/pages/setting/request_permission_page.dart index 6763f73..205dbab 100644 --- a/lib/pages/setting/request_permission_page.dart +++ b/lib/pages/setting/request_permission_page.dart @@ -1 +1 @@ -import 'package:driverapp/app-icons/driver_app_icons.dart'; import 'package:driverapp/config/config.dart'; import 'package:driverapp/core/viewModels/orders_view_model.dart'; import 'package:driverapp/pages/base/base_view.dart'; import 'package:driverapp/root_page.dart'; import 'package:driverapp/uitl/utils.dart'; import 'package:driverapp/widgets/bottom_sheet/action_sheet_button.dart'; import 'package:driverapp/widgets/buttons/secondary_button.dart'; import 'package:driverapp/widgets/data_display/text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:location/location.dart'; import '../../uitl/translations_delegate_base.dart'; import '../../widgets/others/app_scaffold_widget.dart'; class RequestPermissionPage extends StatelessWidget { RequestPermissionPage(); @override Widget build(BuildContext context) { showDeliveryOptions(OrdersViewModel model) { showModalBottomSheet( backgroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.only( topLeft: Radius.circular(50.0), topRight: Radius.circular(50.0), ), ), context: context, builder: (BuildContext bc) { return ListView( children: [ Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(50.0), topRight: Radius.circular(50.0), ), ), child: Column( mainAxisSize: MainAxisSize.min, 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.45, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(50.0), topRight: Radius.circular(50.0), ), ), 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: () {}, ), SizedBox(height: 15), ActionSheetButton( label: TranslationBase.of(context) .deliveredAccepted, icon: DriverApp.not_available, onTap: () {}, ), SizedBox(height: 15), ActionSheetButton( label: TranslationBase.of(context) .deliveredRejected, icon: DriverApp.rejected_icon, onTap: () {}, ), SizedBox(height: 15), ActionSheetButton( label: TranslationBase.of(context).canceled, icon: DriverApp.not_reachable_icon, onTap: () {}, ), SizedBox(height: 15), ], ), ], ), ), ) ], ), ), ], ); }); } return BaseView( builder: (_, model, w) => AppScaffold( isShowAppBar: true, appBarColor: Color(0xff49C1BC), arrowColor: Colors.white, titleColor: Colors.white, appBarTitle: "request Permissions", isAppBarGradient: true, body: Container( child: Container( decoration: BoxDecoration(gradient: LINEAR_GRADIENT), child: ListView( children: [ Column( children: [ Stack( children: [ // Container( // width: MediaQuery.of(context).size.width, // height: MediaQuery.of(context).size.width, // ), Padding( padding: const EdgeInsets.only(top: 75.0), child: Container( width: MediaQuery.of(context).size.width * 1.0, height: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.height * 0.70 : MediaQuery.of(context).size.height * 1.7, margin: EdgeInsets.only( top: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.width * 0.23 : MediaQuery.of(context).size.width * 0.13), decoration: BoxDecoration( color: Theme.of(context).scaffoldBackgroundColor, borderRadius: BorderRadius.only( topLeft: Radius.circular(45), topRight: Radius.circular(45)), ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ SizedBox( height: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.height * 0.05 : MediaQuery.of(context).size.height * 0.29, //MediaQuery.of(context).size.width * 0.005, ), Padding( padding: MediaQuery.of(context).orientation == Orientation.portrait ? EdgeInsets.only(top: 60.0) : EdgeInsets.only(top: 15.0), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text("Delivery app need permission") ], ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.08, ), 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(), ), ], ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.1, ), Container( margin: MediaQuery.of(context).orientation == Orientation.portrait ? EdgeInsets.all(8.0) : EdgeInsets.symmetric(horizontal: 12.0), child: SecondaryButton( label: "Give permission", onTap: () async { Location location = new Location(); await location.requestPermission(); Utils.getLocationPermission() .then((value) { if (value == PermissionStatus.granted) { Navigator.pushReplacement( AppGlobal.context, MaterialPageRoute( builder: (context) => RootPage(), ), ); } }); }, ), ), ], ), ), ), // CustomerBriefCard( // itemId: 11, // customerFirstName: "item.firstName", // customerLastName: "item.lastName", // mobileNo: "item.mobileNumber", // totalPayment: "item.amount", // deliveryTime: "item.orderCreatedOn", // ), ], ), ], ), ], ), ), ), ), ); } } \ No newline at end of file +import 'package:driverapp/config/config.dart'; import 'package:driverapp/core/viewModels/orders_view_model.dart'; import 'package:driverapp/pages/base/base_view.dart'; import 'package:driverapp/root_page.dart'; import 'package:driverapp/uitl/utils.dart'; import 'package:driverapp/widgets/buttons/secondary_button.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:location/location.dart'; import '../../widgets/others/app_scaffold_widget.dart'; class RequestPermissionPage extends StatelessWidget { RequestPermissionPage(); @override Widget build(BuildContext context) { return BaseView( builder: (_, model, w) => AppScaffold( isShowAppBar: true, appBarColor: Color(0xff49C1BC), arrowColor: Colors.white, titleColor: Colors.white, appBarTitle: "Request Permissions", isAppBarGradient: true, body: Container( child: Container( decoration: BoxDecoration(gradient: LINEAR_GRADIENT), child: ListView( children: [ Column( children: [ Stack( children: [ Padding( padding: const EdgeInsets.only(top: 75.0), child: Container( width: MediaQuery.of(context).size.width * 1.0, height: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.height * 0.70 : MediaQuery.of(context).size.height * 1.7, margin: EdgeInsets.only( top: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.width * 0.23 : MediaQuery.of(context).size.width * 0.13), decoration: BoxDecoration( color: Theme.of(context).scaffoldBackgroundColor, borderRadius: BorderRadius.only( topLeft: Radius.circular(45), topRight: Radius.circular(45)), ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ SizedBox( height: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.height * 0.05 : MediaQuery.of(context).size.height * 0.29, //MediaQuery.of(context).size.width * 0.005, ), Padding( padding: MediaQuery.of(context).orientation == Orientation.portrait ? EdgeInsets.only(top: 60.0) : EdgeInsets.only(top: 15.0), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "Delivery app need permission to your location information") ], ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.08, ), 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: [ ], ), ), SizedBox( height: MediaQuery.of(context).size.width * 0.1, ), Container( margin: MediaQuery.of(context).orientation == Orientation.portrait ? EdgeInsets.all(8.0) : EdgeInsets.symmetric(horizontal: 12.0), child: SecondaryButton( label: "request permission", onTap: () async { LocationData loc = await Utils.getLocation(); if (loc != null) { Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => RootPage(), ), ); } // Location location = new Location(); // await location.requestPermission(); // Utils.getLocationPermission() // .then((value) { // if (value == PermissionStatus.granted) { // // } // }); }, ), ), ], ), ), ), ], ), ], ), ], ), ), ), ), ); } } \ No newline at end of file diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index e208311..1ad9f4c 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -4,6 +4,7 @@ import 'package:driverapp/config/config.dart'; import 'package:driverapp/pages/setting/request_permission_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:location/location.dart'; import 'app_shared_preferences.dart'; @@ -48,13 +49,9 @@ class Utils { FocusScope.of(context).unfocus(); } - static isLocationPermissionGranted() async { - return (await location.hasPermission()) == PermissionStatus.granted; - } - - static Location location = new Location(); - - static Future getLocationPermission() async { + static getLocation() async { + Location location = new Location(); + LocationData currentLocation; bool _serviceEnabled; PermissionStatus _permissionGranted; @@ -67,12 +64,18 @@ class Utils { } if (!_serviceEnabled) { // Route to another page and send to him message "You have to enable location" + Navigator.pushReplacement( + AppGlobal.context, + MaterialPageRoute( + builder: (context) => RequestPermissionPage(), + ), + ); } } _permissionGranted = await location.hasPermission(); if (_permissionGranted == PermissionStatus.denied) { -// _permissionGranted = await location.requestPermission(); + _permissionGranted = await location.requestPermission(); if (_permissionGranted == PermissionStatus.denied) { // Route to another page and send to him message "You have to give Permission" Navigator.pushReplacement( @@ -83,29 +86,26 @@ class Utils { ); //return _permissionGranted; } else if (_permissionGranted == PermissionStatus.deniedForever) { - AppSettings.openLocationSettings(); + try { + SystemNavigator.pop(); + AppSettings.openLocationSettings(); + } catch (e) { + print(e); + } // open setting page + } else { + currentLocation = await location.getLocation(); + return currentLocation; } } else if (_permissionGranted == PermissionStatus.deniedForever) { + SystemNavigator.pop(); AppSettings.openLocationSettings(); - // open setting page - } - return _permissionGranted; - } - - static getLocation() async { -// AppGlobal.context - Location location = new Location(); - LocationData currentLocation; -// await getLocationPermission(); - try { + // open setting page + } else { currentLocation = await location.getLocation(); - } catch (e) { -// await getLocationPermission(); - print(e); + return currentLocation; } - return currentLocation; } static formatStringToPascalCase(String name) {