Update Qlyra application
Build Android (FCM) / build-android-fcm (push) Canceled after 0s
Build Android / build-android (push) Canceled after 0s
Build iOS / build-ios (push) Canceled after 0s
Build Linux / build-linux (push) Canceled after 0s
Build macOS / build-macos (push) Canceled after 0s
Build Windows / build-windows (push) Canceled after 0s
Release (main) / android (oneme) (push) Canceled after 0s
Release (main) / android (qlyra) (push) Canceled after 0s
Release (main) / windows (push) Canceled after 0s
Release (main) / linux (push) Canceled after 0s
Release (main) / macos (push) Canceled after 0s
Release (main) / ios (push) Canceled after 0s
Release (main) / release (push) Canceled after 0s
Build Android (FCM) / build-android-fcm (push) Canceled after 0s
Build Android / build-android (push) Canceled after 0s
Build iOS / build-ios (push) Canceled after 0s
Build Linux / build-linux (push) Canceled after 0s
Build macOS / build-macos (push) Canceled after 0s
Build Windows / build-windows (push) Canceled after 0s
Release (main) / android (oneme) (push) Canceled after 0s
Release (main) / android (qlyra) (push) Canceled after 0s
Release (main) / windows (push) Canceled after 0s
Release (main) / linux (push) Canceled after 0s
Release (main) / macos (push) Canceled after 0s
Release (main) / ios (push) Canceled after 0s
Release (main) / release (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
enum LocationAttachmentFailure {
|
||||
serviceDisabled,
|
||||
permissionDenied,
|
||||
unavailable,
|
||||
}
|
||||
|
||||
class LocationAttachmentResult {
|
||||
final Position? position;
|
||||
final LocationAttachmentFailure? failure;
|
||||
|
||||
const LocationAttachmentResult._({this.position, this.failure});
|
||||
|
||||
const LocationAttachmentResult.success(Position value)
|
||||
: this._(position: value);
|
||||
|
||||
const LocationAttachmentResult.failed(LocationAttachmentFailure value)
|
||||
: this._(failure: value);
|
||||
}
|
||||
|
||||
class LocationAttachmentController {
|
||||
Future<LocationAttachmentResult> resolveCurrentPosition() async {
|
||||
try {
|
||||
if (!await Geolocator.isLocationServiceEnabled()) {
|
||||
return const LocationAttachmentResult.failed(
|
||||
LocationAttachmentFailure.serviceDisabled,
|
||||
);
|
||||
}
|
||||
var permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
return const LocationAttachmentResult.failed(
|
||||
LocationAttachmentFailure.permissionDenied,
|
||||
);
|
||||
}
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
),
|
||||
);
|
||||
return LocationAttachmentResult.success(position);
|
||||
} catch (_) {
|
||||
return const LocationAttachmentResult.failed(
|
||||
LocationAttachmentFailure.unavailable,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user