diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index cdbc90e..41cc40e 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -5,6 +5,8 @@ In most cases you can leave this as-is, but you if you want to provide additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> + + _orders = List(); @@ -30,32 +30,37 @@ class OrdersService extends BaseService { ); Future getPendingOrders() async { + // if (await Utils.isLocationPermissionGranted()) { LocationData loc = await Utils.getLocation(); - PendingOrders _requestGetPendingOrders = PendingOrders( - searchKey: "", - pageSize: 0, - pageIndex: 0, - latitude: loc.latitude.toString(), - longitude: loc.longitude.toString(), - ); - hasError = false; - try { - await baseAppClient.post(GET_ALL_ORDERS, - onSuccess: (dynamic response, int statusCode) { - _orders.clear(); - response['PatientER_Delivery_GetAllOrderList'].forEach((order) { - _orders.add(PendingOrdersRes.fromJson(order)); - }); - }, onFailure: (String error, int statusCode) { + + if (loc != null) { + PendingOrders _requestGetPendingOrders = PendingOrders( + searchKey: "", + pageSize: 0, + pageIndex: 0, + latitude: loc.latitude.toString(), + longitude: loc.longitude.toString(), + ); + hasError = false; + try { + await baseAppClient.post(GET_ALL_ORDERS, + onSuccess: (dynamic response, int statusCode) { + _orders.clear(); + response['PatientER_Delivery_GetAllOrderList'].forEach((order) { + _orders.add(PendingOrdersRes.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; + } } + // } } Future insertOrder(ScanQrRequestModel _scanQrRequestModel) async { diff --git a/lib/pages/dashboard/dashboard_screen.dart b/lib/pages/dashboard/dashboard_screen.dart index da4e318..c7bc69b 100644 --- a/lib/pages/dashboard/dashboard_screen.dart +++ b/lib/pages/dashboard/dashboard_screen.dart @@ -41,6 +41,12 @@ class _DashboardScreenState extends State { super.didChangeDependencies(); } + @override + void initState() { + super.initState(); + Utils.getLocationPermission(); + } + @override Widget build(BuildContext context) { int orderId; @@ -53,463 +59,463 @@ class _DashboardScreenState extends State { child: ListView( children: [ Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Padding( - padding: EdgeInsets.all(16.0), - child: Column( - children: [ - SafeArea( + 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( + _authenticationViewModel.user.userName, + style: TextStyle( + fontSize: 22.0, + color: Hexcolor("#343333"), + fontWeight: FontWeight.bold), + ), + ), + ], + ), + ), + ], + ), + ), + 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( - _authenticationViewModel.user.userName, - style: TextStyle( - fontSize: 22.0, - color: Hexcolor("#343333"), - fontWeight: FontWeight.bold), + InkWell( + child: 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, + ), + ), ), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => SettingPage( + driverName: _authenticationViewModel + .user.userName, + driverID: _authenticationViewModel + .user.userID))); + }, ), ], ), ), - ], - ), - ), - Padding( - padding: EdgeInsets.all(16.0), - child: SafeArea( - child: Column( - children: [ - InkWell( - child: 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, - ), - ), - ), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => SettingPage( - driverName: _authenticationViewModel - .user.userName, - driverID: _authenticationViewModel - .user.userID))); - }, - ), - ], ), - ), + ], ), - ], - ), - 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: LINEAR_GRADIENT, - ), - 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: 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 == + children: [ + Text( + TranslationBase.of(context).youHave, + style: TextStyle( + color: Colors.white, + fontSize: MediaQuery.of(context) + .orientation == Orientation.landscape - ? SizeConfig.textMultiplier * + ? SizeConfig.textMultiplier * 2.2 - : SizeConfig.textMultiplier * + : SizeConfig.textMultiplier * 1.3, - ), - ), - Text( - '5', - style: TextStyle( - color: Colors.white, - fontSize: + ), + ), + Text( + '5', + 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 == + ), + Text( + TranslationBase.of(context) + .undeliveredPackages, + style: TextStyle( + color: Colors.white, + fontSize: MediaQuery.of(context) + .orientation == Orientation.landscape - ? SizeConfig.textMultiplier * + ? SizeConfig.textMultiplier * 2.2 - : SizeConfig.textMultiplier * + : 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: + 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 == + 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.09 - : 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: LINEAR_GRADIENT, - ), - child: InkWell( - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - DeliverdOrdersPage())), - child: Row( - 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: LINEAR_GRADIENT, + ), + child: InkWell( + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + DeliverdOrdersPage())), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Padding( - padding: EdgeInsets.all(2.0), - child: Column( - mainAxisAlignment: + 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 == + children: [ + Text( + TranslationBase.of(context).youHave, + style: TextStyle( + color: Colors.white, + fontSize: MediaQuery.of(context) + .orientation == Orientation.landscape - ? SizeConfig.textMultiplier * + ? SizeConfig.textMultiplier * 2.2 - : SizeConfig.textMultiplier * + : SizeConfig.textMultiplier * 1.3, - ), - ), - Text( - '3', - style: TextStyle( - color: Colors.white, - fontSize: + ), + ), + Text( + '3', + style: TextStyle( + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 3.0), - ), - Text( - TranslationBase.of(context) - .deliveredPackages, - style: TextStyle( - color: Colors.white, - fontSize: MediaQuery.of(context) - .orientation == + ), + Text( + TranslationBase.of(context) + .deliveredPackages, + style: TextStyle( + color: Colors.white, + fontSize: MediaQuery.of(context) + .orientation == Orientation.landscape - ? SizeConfig.textMultiplier * + ? SizeConfig.textMultiplier * 2.2 - : SizeConfig.textMultiplier * + : 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: + 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/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.09 - : 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( - onTap: () { - _scanQrAndGetPatient(context, model); - }, - child: Container( - height: MediaQuery.of(context).orientation == + Padding( + padding: EdgeInsets.symmetric(vertical: 16.0, horizontal: 15.0), + child: Row( + children: [ + Expanded( + child: InkWell( + onTap: () { + _scanQrAndGetPatient(context, model); + }, + 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: LINEAR_GRADIENT, - ), - 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: LINEAR_GRADIENT, + ), + 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: [ - Padding( - padding: EdgeInsets.only(top: 8.0), - child: Text( - TranslationBase.of(context).scan, - style: TextStyle( - fontSize: MediaQuery.of(context) - .orientation == + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.only(top: 8.0), + child: Text( + TranslationBase.of(context).scan, + style: TextStyle( + fontSize: MediaQuery.of(context) + .orientation == Orientation.landscape - ? SizeConfig.textMultiplier * 6.0 - : SizeConfig.textMultiplier * 4.0, - color: Colors.white, - fontWeight: FontWeight.w400, + ? SizeConfig.textMultiplier * 6.0 + : SizeConfig.textMultiplier * 4.0, + color: Colors.white, + fontWeight: FontWeight.w400, + ), + ), ), - ), - ), - Padding( - padding: EdgeInsets.only(top: 0.0), - child: Text( - TranslationBase.of(context) - .toAddPackageToQue, - style: TextStyle( - fontSize: MediaQuery.of(context) - .orientation == + Padding( + padding: EdgeInsets.only(top: 0.0), + child: Text( + TranslationBase.of(context) + .toAddPackageToQue, + style: TextStyle( + fontSize: MediaQuery.of(context) + .orientation == Orientation.landscape - ? SizeConfig.textMultiplier * 3.0 - : SizeConfig.textMultiplier * 2.0, - color: Colors.white, - letterSpacing: 0.2, - wordSpacing: 0.5, + ? SizeConfig.textMultiplier * 3.0 + : SizeConfig.textMultiplier * 2.0, + color: Colors.white, + letterSpacing: 0.2, + wordSpacing: 0.5, + ), + ), ), - ), - ), + ], + ) ], - ) - ], + ), + ), ), - ), - ), - ) - ], - ), - ), - 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: 18.0, - color: Hexcolor("#343333"), - fontWeight: FontWeight.bold)), + ) ], ), - if (model.state == ViewState.Idle) - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - InkWell( - child: Row( - children: [ - Text( - TranslationBase.of(context).seeAll, - style: TextStyle( - fontSize: 14.5, color: Color(0xff42B6AD)), + ), + 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: 18.0, + color: Hexcolor("#343333"), + fontWeight: FontWeight.bold)), + ], + ), + if (model.state == ViewState.Idle) + 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), + ), + ], ), - 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 < 3 ? model.orders.length : 3, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 0.2), + child: OrderInfoCard( + order: model.orders[index], + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => InformationPage( + model.orders[index]))); + }), + ); + }, ), - ], - ), - ), - NetworkBaseView( - baseViewModel: model, - child: Expanded( - child: ListView.builder( - shrinkWrap: true, - scrollDirection: Axis.vertical, - itemCount: model.orders == null - ? 0 - : model.orders.length < 3 ? model.orders.length : 3, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: EdgeInsets.symmetric(horizontal: 0.2), - child: OrderInfoCard( - order: model.orders[index], - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => InformationPage( - model.orders[index]))); - }), - ); - }, + ), ), - ), + ], ), - ], + ), ), - ), - ), ); } diff --git a/lib/pages/setting/request_permission_page.dart b/lib/pages/setting/request_permission_page.dart new file mode 100644 index 0000000..6763f73 --- /dev/null +++ b/lib/pages/setting/request_permission_page.dart @@ -0,0 +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 diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index 5fbc743..841544a 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -1,5 +1,9 @@ +import 'package:app_settings/app_settings.dart'; import 'package:connectivity/connectivity.dart'; +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:location/location.dart'; import 'app_shared_preferences.dart'; @@ -21,7 +25,7 @@ class Utils { /// Check The Internet Connection static Future checkConnection() async { ConnectivityResult connectivityResult = - await (Connectivity().checkConnectivity()); + await (Connectivity().checkConnectivity()); if ((connectivityResult == ConnectivityResult.mobile) || (connectivityResult == ConnectivityResult.wifi)) { return true; @@ -44,9 +48,63 @@ class Utils { FocusScope.of(context).unfocus(); } + static isLocationPermissionGranted() async { + return (await location.hasPermission()) == PermissionStatus.granted; + } + + static Location location = new Location(); + + static Future getLocationPermission() async { + bool _serviceEnabled; + PermissionStatus _permissionGranted; + + _serviceEnabled = await location.serviceEnabled(); + if (!_serviceEnabled) { + try { + _serviceEnabled = await location.requestService(); + } catch (e) { + print(e); + } + if (!_serviceEnabled) { + // Route to another page and send to him message "You have to enable location" + } + } + + _permissionGranted = await location.hasPermission(); + if (_permissionGranted == PermissionStatus.denied) { +// _permissionGranted = await location.requestPermission(); + if (_permissionGranted == PermissionStatus.denied) { + // Route to another page and send to him message "You have to give Permission" + Navigator.pushReplacement( + AppGlobal.context, + MaterialPageRoute( + builder: (context) => RequestPermissionPage(), + ), + ); + //return _permissionGranted; + } else if (_permissionGranted == PermissionStatus.deniedForever) { + AppSettings.openLocationSettings(); + // open setting page + } + } else if (_permissionGranted == PermissionStatus.deniedForever) { + AppSettings.openLocationSettings(); + // open setting page + } + return _permissionGranted; + } + static getLocation() async { +// AppGlobal.context Location location = new Location(); - LocationData currentLocation = await location.getLocation(); + LocationData currentLocation; +// await getLocationPermission(); + + try { + currentLocation = await location.getLocation(); + } catch (e) { + await getLocationPermission(); + print(e); + } return currentLocation; } diff --git a/pubspec.yaml b/pubspec.yaml index 57e9498..90596bc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -75,6 +75,9 @@ dependencies: #gradient gradient_app_bar: ^0.1.3 + app_settings: ^4.0.3 + +