-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.dart
33 lines (29 loc) · 1.07 KB
/
location.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'package:geolocator/geolocator.dart';
/// A class that provides methods for interacting with location services.
class LocationApi {
/// Checks the permission status for accessing the device's location.
///
/// Returns the current permission status.
Future<LocationPermission> permissionStatus() async {
return await Geolocator.checkPermission();
}
/// Requests permission to access the device's location.
///
/// Returns `true` if the permission is granted, `false` otherwise.
Future<LocationPermission> requestPermission() async {
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
permission = LocationPermission.deniedForever;
}
}
return permission;
}
/// Retrieves the current device location.
///
/// Returns the current device position.
Future<Position> getCurrentLocation() async {
return await Geolocator.getCurrentPosition();
}
}