27 lines
654 B
Dart
27 lines
654 B
Dart
import 'package:location/location.dart';
|
|
|
|
Location location = Location();
|
|
location.enableBackgroundMode(enable: true)
|
|
|
|
bool serviceEnabled;
|
|
PermissionStatus permissionGranted;
|
|
LocationData locationData;
|
|
|
|
serviceEnabled = await location.serviceEnabled();
|
|
if (!serviceEnabled) {
|
|
serviceEnabled = await location.requestService();
|
|
if (!serviceEnabled) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
permissionGranted = await location.hasPermission();
|
|
if (permissionGranted == PermissionStatus.denied) {
|
|
permissionGranted = await location.requestPermission();
|
|
if (permissionGranted != PermissionStatus.granted) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
locationData = await location.getLocation();
|