|
|
|
|
@ -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<PermissionStatus> 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,30 +86,27 @@ class Utils {
|
|
|
|
|
);
|
|
|
|
|
//return _permissionGranted;
|
|
|
|
|
} else if (_permissionGranted == PermissionStatus.deniedForever) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static formatStringToPascalCase(String name) {
|
|
|
|
|
List<String> names = name.split(" ");
|
|
|
|
|
|