Skip to content

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

@alejandromoreno-rudo

Description

@alejandromoreno-rudo

Please check the following before submitting a new issue.

Please select affected platform(s)

  • 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
  Future<PositionEntity?> 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

Version

14.0.2

Flutter Doctor output

Doctor output
[✓] 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!```

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions