|
|
|
@ -1,5 +1,9 @@
|
|
|
|
|
|
|
|
import 'package:app_settings/app_settings.dart';
|
|
|
|
import 'package:connectivity/connectivity.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/cupertino.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:location/location.dart';
|
|
|
|
import 'package:location/location.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import 'app_shared_preferences.dart';
|
|
|
|
import 'app_shared_preferences.dart';
|
|
|
|
@ -44,9 +48,63 @@ class Utils {
|
|
|
|
FocusScope.of(context).unfocus();
|
|
|
|
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 {
|
|
|
|
static getLocation() async {
|
|
|
|
|
|
|
|
// AppGlobal.context
|
|
|
|
Location location = new Location();
|
|
|
|
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;
|
|
|
|
return currentLocation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|