Baseflow / Baseflow/flutter-geolocator

[Bug]: getCurrentPosition future keeps waiting when enabling device location

Open
#1,775 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
1.3k
Forks
803
Avg merge
8h 16m
Merged PRs (30d)
1

Description

### Please check the following before submitting a new issue.

- [x] I have searched the [existing issues](https://github.com/baseflow/flutter-geolocator/issues).
- [x] I have carefully [read the documentation](https://github.com/Baseflow/flutter-geolocator/blob/main/geolocator/README.md) and verified I have added the required platform specific configuration.

### Please select affected platform(s)

- [x] Android
- [ ] iOS
- [ ] Linux
- [ ] macOS
- [ ] Web
- [ ] Windows

### Steps to reproduce

_The error appears on an Oppo Reno 4 Z (Android 12) and on a Xiaomi 11T (Android 14), but it works properly on a Google Pixel 10 Pro (Android 16)_

1.- Run the app on a physical Android Device
2.- Disable location on the phone (not permission)
3.- Enable the location again
4.- Call `await Geolocator.getCurrentPosition(locationSettings: settings)`

### Expected results

Retrieves the user current position

### Actual results

The future isn't resolving and keeps waiting.
When adding a timeLimit in locationSettings we retrieve a TimeOutException.

### Code sample

Code sample

```dart
Future getPosition() async {
try {
final settings = getLocationSettings(locationType: LocationType.foreground);
final position = await Geolocator.getCurrentPosition(locationSettings: settings);

if (position.isMocked) return null;
return PositionEntity(
latitude: position.latitude,
longitude: position.longitude,
);
} catch (error) {
_logger.error(message: 'Error getting position: $error');
return null;
}
}

LocationSettings getLocationSettings({required LocationType locationType}) {
final int trackingDistanceInMeters = 10;
final int trackingIntervalSeconds = 300;

final backgroundNotificationTitle = Internationalize.location.backgroundNotificationTitle;
final backgroundNotificationMessage = Internationalize.location.backgroundNotificationMessage;

late LocationSettings locationSettings;
if (Platform.isAndroid) {
locationSettings = AndroidSettings(
accuracy: LocationAccuracy.high,
// When adding timeLimit it throws a TimeOutException
// timeLimit: locationType == LocationType.foreground ? Duration(seconds: 5) : null,
distanceFilter: trackingDistanceInMeters,
intervalDuration: Duration(seconds: trackingIntervalSeconds),
foregroundNotificationConfig: locationType == LocationType.background
? ForegroundNotificationConfig(
notificationTitle: backgroundNotificationTitle,
notificationText: backgroundNotificationMessage,
notificationIcon: AndroidResource(name: 'ic_notification', defType: 'drawable'),
enableWakeLock: true,
)
: null,
);
} else if (Platform.isIOS) {
locationSettings = AppleSettings(
accuracy: LocationAccuracy.high,
activityType: ActivityType.fitness,
distanceFilter: trackingDistanceInMeters,
pauseLocationUpdatesAutomatically: true,
showBackgroundLocationIndicator: locationType == LocationType.background,
);
} else {
locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: trackingDistanceInMeters,
);
}
return locationSettings;
}
```

### Screenshots or video

Screenshots or video demonstration

[Grabación de pantalla 2026-03-23 a las 10.21.20.mp4.zip](https://github.com/user-attachments/files/26178333/Grabacion.de.pantalla.2026-03-23.a.las.10.21.20.mp4.zip)

### Version

14.0.2

### Flutter Doctor output

Doctor output

```console
[✓] Flutter (Channel stable, 3.41.2, on macOS 26.2 25C56 darwin-arm64, locale es-ES) [645ms]
• Flutter version 3.41.2 on channel stable at /Users/alejandromorenoaristizabal/fvm/versions/3.41.2
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 90673a4eef (5 weeks ago), 2026-02-18 13:54:59 -0800
• Engine revision 6c0baaebf7
• Dart version 3.11.0
• DevTools version 2.54.1
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [2,5s]
• Android SDK at /Users/alejandromorenoaristizabal/Library/Android/sdk
• Emulator version 35.4.9.0 (build_id 13025442) (CL:N/A)
• Platform android-36, build-tools 36.0.0
• ANDROID_HOME = /Users/alejandromorenoaristizabal/Library/Android/sdk
• Java binary at: /Users/alejandromorenoaristizabal/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 26.2) [2,6s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 17C52
• CocoaPods version 1.16.2

[✓] Chrome - develop for the web [6ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (4 available) [7,4s]
• CPH2065 (mobile) • GMTWAEKJ69UGQONZ • android-arm64 • Android 12 (API 31)
• iPhone (Pablo Suárez) (wireless) (mobile) • 00008030-0001203A36DA802E • ios • iOS 26.3.1 23D8133
• macOS (desktop) • macos • darwin-arm64 • macOS 26.2 25C56 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 146.0.7680.153
! Error: Browsing on the local area network for iPhone MA. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources [488ms]
• All expected network resources are available.

• No issues found!```

Contributor guide

Open the contributing guide

Research direction

Start at Geolocator.getCurrentPosition with the AndroidSettings shown in the issue, and reproduce the sequence of disabling and re-enabling device location on the listed Android devices. Compare the behavior with the Pixel result and determine what should happen when the future waits indefinitely; done means the current position resolves reliably after location is re-enabled or the behavior is bounded by the configured time limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, dart, flutter
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.