Merge branch 'spike/block2-derisking'
This commit is contained in:
commit
dc599dae30
9 changed files with 69 additions and 31 deletions
|
|
@ -16,23 +16,38 @@ class GeolocatorCoarseLocation implements CoarseLocationProvider {
|
|||
@override
|
||||
Future<({double lat, double lon})?> currentCoarseLatLon() async {
|
||||
try {
|
||||
if (!await Geolocator.isLocationServiceEnabled()) return null;
|
||||
var permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
// Give the user a way out of a permanent denial.
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
await Geolocator.openAppSettings();
|
||||
return null;
|
||||
}
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(
|
||||
accuracy: LocationAccuracy.low,
|
||||
),
|
||||
);
|
||||
if (permission == LocationPermission.denied) return null;
|
||||
if (!await Geolocator.isLocationServiceEnabled()) {
|
||||
await Geolocator.openLocationSettings();
|
||||
return null;
|
||||
}
|
||||
|
||||
// A fresh coarse fix can take a while (or never come indoors); fall back
|
||||
// to the last known position so the button stays responsive.
|
||||
Position? position;
|
||||
try {
|
||||
position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(
|
||||
accuracy: LocationAccuracy.low,
|
||||
timeLimit: Duration(seconds: 12),
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
position = await Geolocator.getLastKnownPosition();
|
||||
}
|
||||
if (position == null) return null;
|
||||
return (lat: position.latitude, lon: position.longitude);
|
||||
} catch (_) {
|
||||
return null; // service off, plugin unsupported (desktop), timeout, …
|
||||
return null; // plugin unsupported (desktop), etc.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue