Is there a way to find out in Flutter if the GPS is activated or deactivated? I use the plugin location however there I get only the location and not the state of the GPS.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
With geolocations you can check wether the location service is operational. It generally includes more customizability then the location package.
final GeolocationResult result = await Geolocation.isLocationOperational();
if(result.isSuccessful) {
// location service is enabled, and location permission is granted
} else {
// location service is not enabled, restricted, or location permission is denied
}
回答2:
Accepted answer uses outdated plugin, you can use Geolocator plugin,
var geoLocator = Geolocator();
var status = await geoLocator.checkGeolocationPermissionStatus();
if (status == GeolocationStatus.denied)
// Take user to permission settings
else if (status == GeolocationStatus.disabled)
// Take user to location page
else if (status == GeolocationStatus.restricted)
// Restricted
else if (status == GeolocationStatus.unknown)
// Unknown
else if (status == GeolocationStatus.granted)
// Permission granted and location enabled