Open bardram opened 3 years ago
Use the location package and implement the following code:
https://pub.dev/packages/location
import 'package:location/location.dart';
Future<bool> checkLocationPermission() async {
Location location = new Location();
bool _serviceEnabled;
PermissionStatus _permissionGranted;
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return false;
}
}
_permissionGranted = await location.hasPermission();
switch (_permissionGranted) {
case PermissionStatus.denied:
case PermissionStatus.deniedForever:
final permission = await location.requestPermission();
if (permission == PermissionStatus.granted) {
location.enableBackgroundMode(enable: true);
return true;
} else {
return false;
}
case PermissionStatus.granted:
case PermissionStatus.grantedLimited:
return true;
default:
return false;
}
}
Since the
location_permissions
plugin is discontinued, maybe the example app should be updated to use thepermission_handler
plugin?