request_permission on location

location
Elham Rababah 6 years ago
parent c7c51ff55a
commit fcfb19963c

@ -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. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="driver App"

@ -1,14 +1,14 @@
import 'package:driverapp/config/config.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_req_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/base_service.dart';
import 'package:driverapp/core/model/orders/deliverd_order_req_model.dart';
import 'package:driverapp/uitl/utils.dart';
import 'package:location/location.dart';
import 'package:driverapp/core/model/orders/deliverd_order_res_model.dart';
class OrdersService extends BaseService {
List<PendingOrdersRes> _orders = List();
@ -30,7 +30,10 @@ class OrdersService extends BaseService {
);
Future getPendingOrders() async {
// if (await Utils.isLocationPermissionGranted()) {
LocationData loc = await Utils.getLocation();
if (loc != null) {
PendingOrders _requestGetPendingOrders = PendingOrders(
searchKey: "",
pageSize: 0,
@ -57,6 +60,8 @@ class OrdersService extends BaseService {
throw e;
}
}
// }
}
Future insertOrder(ScanQrRequestModel _scanQrRequestModel) async {
hasError = false;

@ -41,6 +41,12 @@ class _DashboardScreenState extends State<DashboardScreen> {
super.didChangeDependencies();
}
@override
void initState() {
super.initState();
Utils.getLocationPermission();
}
@override
Widget build(BuildContext context) {
int orderId;

File diff suppressed because one or more lines are too long

@ -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';
@ -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<PermissionStatus> 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;
}

@ -75,6 +75,9 @@ dependencies:
#gradient
gradient_app_bar: ^0.1.3
app_settings: ^4.0.3

Loading…
Cancel
Save