The name 'GeolocationStatus' isn't a type so it can't be used as a type argument

137 Views Asked by At

Im getting error under the GeolocationStatus Enum. what seem to be the problem `

return FutureBuilder<GeolocationStatus>(
    future: Geolocator.isLocationServiceEnabled(),
    builder:
        (BuildContext context, AsyncSnapshot<GeolocationStatus> snapshot) {
      if (!snapshot.hasData) {
        return const Center(child: CircularProgressIndicator());
      }

      if (snapshot.data == GeolocationStatus.denied) {
      }

`

Is there solution to this?

1

There are 1 best solutions below

0
On

Geolocator.isLocationServiceEnabled is a function that has a return type of Future<bool>. It does not return the status of location service, but a bool value whether it is enabled or not.

Try to create the FutureBuilder like this:

return FutureBuilder<bool>(
    future: Geolocator.isLocationServiceEnabled(),
    builder:
        (context, snapshot) {
      if (!snapshot.hasData) {
        return const Center(child: CircularProgressIndicator());
      }

      // will be true if the service is enabled
      if (snapshot.data!) {
      }