icecase
icecase

Reputation: 51

Flutter Geolocator.isLocationServiceEnabled() isn't working as intended

I'm trying to access a location in Flutter via the Geolocator package. This works well but the location permission check has some sort of bug.

I check if the location service is enabled. Once it's accessed i check the users permission and then return location. This works quite as intended, but there is a problem with the first step. I use

Geolocator.isLocationServiceEnabled()

to check if the location service is enabled. Unfortunately, this function just returns in some cases which leads to the whole function not returning, even though the location service is activated.

I already searched in different forums for answers and it seems to be a known problem although i didn't find a solution yet.

Attemps i tried to get access to GPS but failed:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

in AndroidManifest

I could just access the location if i re-run debugging, but not each time...

Does anybody have a clue how to get this built-in function to work as intended?

Thanks in advance!

Upvotes: 2

Views: 2244

Answers (1)

icecase
icecase

Reputation: 51

I found a workaround. I used the permission_handler package and replaced

Geolocator.isLocationServiceEnabled()

with

final hasPermission = await Permission.locationWhenInUse.serviceStatus.isEnabled;

Upvotes: 1

Related Questions