androidflutterdartgeolocation

How to fix the error: The named parameter 'settings' isn't defined when invoking Geolocator.getCurrentPosition


The error:

The named parameter 'settings' isn't defined.

The code:

  Future<Position?> getCurrentLocation() async {
    if (_permissionStatus != LocationPermission.always && _permissionStatus != LocationPermission.whileInUse) {
      await checkLocationPermissions();
      if (_permissionStatus != LocationPermission.always && _permissionStatus != LocationPermission.whileInUse) {
        return null;
      }
    }

    try {
      return await Geolocator.getCurrentPosition(settings: const LocationSettings(accuracy: LocationAccuracy.high));
    } catch (e) {
      //print("Error getting location: $e");
      return null;
    }
  }

pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.8
  http: ^1.4.0
  geolocator: ^14.0.1

I ran these to update the cache.

flutter clean
flutter pub cache repair
flutter pub get

I ran flutter doctor -v

[√] Flutter (Channel stable, 3.32.1, on Microsoft Windows [Version 10.0.22000.3260], locale en-US) [548ms]
    • Flutter version 3.32.1 on channel stable at C:\Users\nicholdw\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b25305a883 (3 weeks ago), 2025-05-29 10:40:06 -0700
    • Engine revision 1425e5e9ec
    • Dart version 3.8.1
    • DevTools version 2.45.1

[√] Windows Version (11 Enterprise 64-bit, 21H2, 2009) [2.6s]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [3.3s]
    • Android SDK at C:\Users\nicholdw\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: C:\Program Files\Eclipse Adoptium\jdk-17.0.15.6-hotspot\bin\java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Temurin-17.0.15+6 (build 17.0.15+6)
    • All Android licenses accepted.

[√] Chrome - develop for the web [186ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Enterprise 2022 17.14.6 (June 2025)) [184ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Enterprise
    • Visual Studio Enterprise 2022 version 17.14.36212.18
    • Windows 10 SDK version 10.0.26100.0

[√] Android Studio (version 2024.3.2) [26ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)

[√] VS Code (version 1.101.0) [24ms]
    • VS Code at C:\Users\nicholdw\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.112.0

[√] Connected device (4 available) [555ms]
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 16 (API 36) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22000.3260]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 137.0.7151.104
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 137.0.3296.83

[√] Network resources [481ms]
    • All expected network resources are available.

• No issues found!

Solution

  • You are getting this error because in geolocator version 14.0.1, the getCurrentPosition method does not accept a named parameter called settings. Instead, it uses locationSettings.

    So, instead of this:

    Geolocator.getCurrentPosition(
      settings: const LocationSettings(accuracy: LocationAccuracy.high),
    );
    

    You should write:

    Geolocator.getCurrentPosition(
      locationSettings: const LocationSettings(accuracy: LocationAccuracy.high),
    );