Preet Shah
Preet Shah

Reputation: 1037

Flutter check GPS status continuously

I'm working on an application that requires the user location continuously. If the user disables GPS, I want to show an error screen. How do I do it using a provider maybe?

Upvotes: 1

Views: 827

Answers (1)

Sanjay Sharma
Sanjay Sharma

Reputation: 4035

You can use permission_handler plugin. You can do the task which requires location permission inside if block and shows the error message if the permission is revoked.

if (await Permission.locationWhenInUse.serviceStatus.isEnabled) {
  // Use location.
} else {
  // show error
}

You can also check this answer which can help you to listen to the permission change.

Upvotes: 2

Related Questions