checkIfSensorEnabled method

dynamic checkIfSensorEnabled()

Implementation

checkIfSensorEnabled() async {
  if(!(await Geolocator.isLocationServiceEnabled())){
    print("GPS sensor not available/enabled.");
    throw PlatformException(code: "SENSOR_NOT_AVAILABLE", message: "GPS sensor not available/enabled.");
  }

  LocationPermission permission = await Geolocator.checkPermission();

  if(permission == LocationPermission.denied){
    permission = await Geolocator.requestPermission();
    if(permission == LocationPermission.denied){
      print("User has denied location permission.");
      throw Exception("User has denied location permission.");
    }
  }

  if(permission == LocationPermission.deniedForever){
    print("User has denied location permission permanently.");
    throw Exception("User has denied location permission permanently.");
  }
}