rekabhq / background_locator

A Flutter plugin for updating location in background.
MIT License
289 stars 330 forks source link

The 'location_permissions' plugin is discontinued #283

Open bardram opened 3 years ago

bardram commented 3 years ago

Since the location_permissions plugin is discontinued, maybe the example app should be updated to use the permission_handler plugin?

sultan18kh commented 2 years ago

Use the location package and implement the following code:

https://pub.dev/packages/location

import 'package:location/location.dart';

Future<bool> checkLocationPermission() async {
    Location location = new Location();

    bool _serviceEnabled;
    PermissionStatus _permissionGranted;

    _serviceEnabled = await location.serviceEnabled();
    if (!_serviceEnabled) {
      _serviceEnabled = await location.requestService();
      if (!_serviceEnabled) {
        return false;
      }
    }

    _permissionGranted = await location.hasPermission();

    switch (_permissionGranted) {
      case PermissionStatus.denied:
      case PermissionStatus.deniedForever:
        final permission = await location.requestPermission();
        if (permission == PermissionStatus.granted) {
          location.enableBackgroundMode(enable: true);
          return true;
        } else {
          return false;
        }
      case PermissionStatus.granted:
      case PermissionStatus.grantedLimited:
        return true;
      default:
        return false;
    }
  }