isLocationServiceEnabled function

Future<bool> isLocationServiceEnabled()

checks if location service is enabled.

Implementation

Future<bool> isLocationServiceEnabled() async {
  final _logger = AtSignLogger('isLocationServiceEnabled');

  try {
    bool serviceEnabled;
    LocationPermission permission;

    serviceEnabled = await Geolocator.isLocationServiceEnabled();

    if (!serviceEnabled) {
      return false;
    }

    permission = await Geolocator.checkPermission();

    if (permission == LocationPermission.deniedForever) {
      return false;
    }

    if (permission == LocationPermission.denied) {
      permission = await Geolocator.requestPermission();
      if (permission == LocationPermission.deniedForever) {
        return false;
      }

      if (permission == LocationPermission.denied) {
        return false;
      }
    }

    return true;
  } catch (e) {
    if (e is PermissionRequestInProgressException) {
      _logger.severe('PermissionRequestInProgressException error $e');
    } else {
      _logger.severe('$e');
    }
    return false;
  }
}