'Couldn't resolve the package 'geolocator' in 'package:geolocator/geolocator.dart'

Install geolocator 8.0.0, everything is normal. But when I go to run the project I get all these errors, even though I import the library correctly.

class GoogleMapsPage extends StatefulWidget {
 const GoogleMapsPage({Key? key}) : super(key: key);

 @override
 State<GoogleMapsPage> createState() => _GoogleMapsPageState();
}

class _GoogleMapsPageState extends State<GoogleMapsPage> {
late GoogleMapController mapController;

final LatLng _center = const LatLng(-16.39882897344725, -71.53693778929792);
late Position position;
String long = "", lat = "";
void _onMapCreated(GoogleMapController controller) {
  mapController = controller;
}

getLocation() async {
  position = await Geolocator.getCurrentPosition(
      desiredAccuracy: LocationAccuracy.high);
  print(position.longitude); 
  print(position.latitude); 

  long = position.longitude.toString();
  lat = position.latitude.toString();

  LocationSettings locationSettings = const LocationSettings(
    accuracy: LocationAccuracy.high, 
    distanceFilter: 100, 
  );
}

The errors are

Error: Couldn't resolve the package 'geolocator' in 'package:geolocator/geolocator.dart'. : Error: Not found: 'package:geolocator/geolocator.dart'core/…/lib/dependencies.dart:26 export 'package:geolocator/geolocator.dart';

Error: Type 'Position' not found. package:provide_geographical_map/…/pages/google_maps_page.dart:21 late Position position; ^^^^^^^^ : Error: 'Position' isn't a type. package:provide_geographical_map/…/pages/google_maps_page.dart:21 late Position position; ^^^^^^^^ : Error: 'LocationSettings' isn't a type. package:provide_geographical_map/…/pages/google_maps_page.dart:40 LocationSettings locationSettings = const LocationSettings( ^^^^^^^^^^^^^^^^ : Error: Undefined name 'LocationAccuracy'. package:provide_geographical_map/…/pages/google_maps_page.dart:41 accuracy: LocationAccuracy.high, ^^^^^^^^^^^^^^^^ : Error: Couldn't find constructor 'LocationSettings'. package:provide_geographical_map/…/pages/google_maps_page.dart:40

LocationSettings locationSettings = const LocationSettings(

Error: The getter 'Geolocator' isn't defined for the class '_GoogleMapsPageState'. package:provide_geographical_map/…/pages/google_maps_page.dart:28

  • '_GoogleMapsPageState' is from 'package:provide_geographical_map/src/presentation/pages/google_maps_page.dart' ('features/provide_geographical_map/lib/src/presentation/pages/google_maps_page.dart'). package:provide_geographical_map/…/pages/google_maps_page.dart:1 Try correcting the name to the name of an existing getter, or defining a getter or field named 'Geolocator'. position = await Geolocator.getCurrentPosition( ^^^^^^^^^^ : Error: The getter 'LocationAccuracy' isn't defined for the class '_GoogleMapsPageState'. package:provide_geographical_map/…/pages/google_maps_page.dart:29
  • '_GoogleMapsPageState' is from 'package:provide_geographical_map/src/presentation/pages/google_maps_page.dart' ('features/provide_geographical_map/lib/src/presentation/pages/google_maps_page.dart'). package:provide_geographical_map/…/pages/google_maps_page.dart:1 Try correcting the name to the name of an existing getter, or defining a getter or field named 'LocationAccuracy'. desiredAccuracy: LocationAccuracy.high); ^^^^^^^^^^^^^^^^


Sources

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

Source: Stack Overflow

Solution Source