'MissingPluginException(No implementation found in flutter using geolocator

i am using geolocator in flutter project to get current location but this error come on it. i added all dependencies in both ios and android files still get this error i dont know why flutter channel stable, 2.12,

here is my code:

Position position = await Geolocato.getCurrentPosition( desiredAccuracy: LocationAccuracy.high);

here is my error coming which i tested android 10, 8 also, but answer same

Unhandled Exception: MissingPluginException(No implementation found for method getCurrentPosition on channel flutter.baseflow.com/geolocator)

i am using geolocator plugin here is plugin link :https://pub.dev/packages/geolocator



Solution 1:[1]

Maybe someone will need my solution. This happens because GeolocatorPlatform.instance is not initialized. Call _registerPlatformInstance() where you need.

import 'package:geolocator_android/geolocator_android.dart';
import 'package:geolocator_apple/geolocator_apple.dart';

void _registerPlatformInstance() {
    if (Platform.isAndroid) {
      GeolocatorAndroid.registerWith();
    } else if (Platform.isIOS) {
      GeolocatorApple.registerWith();
    }
}

Solution 2:[2]

Running flutter clean and flutter pub get fixed the issue for me. I uninstalled the application, cleared the cache of my device and rebuilt the app. This time there was a popup asking to give location permission to the app.

I gave the access and got the current position of the device (latitude and longitude).

Also make sure you upgrade flutter to 3.0.0 by running flutter upgrade

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roman Stakhovskiy
Solution 2 Anubhav Bagri