|
- import 'dart:async';
-
- import 'package:location_platform_interface/location_platform_interface.dart';
-
- export 'package:location_platform_interface/location_platform_interface.dart'
- show PermissionStatus, LocationAccuracy, LocationData;
-
- class Location {
- /// Initializes the plugin and starts listening for potential platform events.
- factory Location() => instance;
-
- Location._();
-
- static final Location instance = Location._();
-
- /// Change settings of the location request.
- ///
- /// The [accuracy] argument is controlling the precision of the
- /// [LocationData]. The [interval] and [distanceFilter] are controlling how
- /// often a new location is sent through [onLocationChanged].
- ///
- /// [interval] and [distanceFilter] are not used on web.
- Future<bool> changeSettings({
- LocationAccuracy accuracy = LocationAccuracy.high,
- int interval = 1000,
- double distanceFilter = 0,
- }) {
- return LocationPlatform.instance.changeSettings(
- accuracy: accuracy,
- interval: interval,
- distanceFilter: distanceFilter,
- );
- }
-
- /// Gets the current location of the user.
- ///
- /// Throws an error if the app has no permission to access location.
- /// Returns a [LocationData] object.
- Future<LocationData> getLocation() async {
- return LocationPlatform.instance.getLocation();
- }
-
- /// Checks if the app has permission to access location.
- ///
- /// If the result is [PermissionStatus.deniedForever], no dialog will be
- /// shown on [requestPermission].
- /// Returns a [PermissionStatus] object.
- Future<PermissionStatus> hasPermission() {
- return LocationPlatform.instance.hasPermission();
- }
-
- /// Checks if the app has permission to access location.
- ///
- /// If the result is [PermissionStatus.deniedForever], no dialog will be
- /// shown on [requestPermission].
- /// Returns a [PermissionStatus] object.
- Future<PermissionStatus> requestPermission() {
- return LocationPlatform.instance.requestPermission();
- }
-
- /// Checks if the location service is enabled.
- Future<bool> serviceEnabled() {
- return LocationPlatform.instance.serviceEnabled();
- }
-
- /// Request the activation of the location service.
- Future<bool> requestService() {
- return LocationPlatform.instance.requestService();
- }
-
- /// Returns a stream of [LocationData] objects.
- /// The frequency and accuracy of this stream can be changed with
- /// [changeSettings]
- ///
- /// Throws an error if the app has no permission to access location.
- Stream<LocationData> get onLocationChanged {
- return LocationPlatform.instance.onLocationChanged;
- }
- }
|