【发布时间】:2021-08-04 07:51:48
【问题描述】:
我收到以下错误:
无法通过实例访问静态方法“getPositionStream”。 尝试使用“Geolocator”类来访问 method.dart(instance_access_to_static_member
和
方法“placemarkFromCoordinates”没有为“Geolocator”类型定义。 尝试将名称更正为现有方法的名称,或定义名为 'placemarkFromCoordinates'.dart(undefined_method) 的方法
Set<Marker> _markers = {};
// this polys will be displayed on the map
Set<Polyline> _poly = {};
// this polys temporarely store the polys to destination
Set<Polyline> _routeToDestinationPolys = {};
// this polys temporarely store the polys to driver
Set<Polyline> _routeToDriverpoly = {};
GoogleMapsServices _googleMapsServices = GoogleMapsServices();
GoogleMapController _mapController;
Geoflutterfire geo = Geoflutterfire();
static LatLng _center;
LatLng _lastPosition = _center;
TextEditingController pickupLocationControlelr = TextEditingController();
TextEditingController destinationController = TextEditingController();
Position position;
DriverService _driverService = DriverService();
// draggable to show
Show show = Show.DESTINATION_SELECTION;
// taxi pin
BitmapDescriptor carPin;
// location pin
BitmapDescriptor locationPin;
LatLng get center => _center;
LatLng get lastPosition => _lastPosition;
Set<Marker> get markers => _markers;
Set<Polyline> get poly => _poly;
GoogleMapController get mapController => _mapController;
RouteModel routeModel;
// Driver request related variables
bool lookingForDriver = false;
bool alertsOnUi = false;
bool driverFound = false;
bool driverArrived = false;
RideRequestServices _requestServices = RideRequestServices();
int timeCounter = 0;
double percentage = 0;
Timer periodicTimer;
String requestedDestination;
String requestStatus = "";
double requestedDestinationLat;
double requestedDestinationLng;
RideRequestModel rideRequestModel;
BuildContext mainContext;
// this variable will listen to the status of the ride request
StreamSubscription<QuerySnapshot> requestStream;
// this variable will keep track of the drivers position before and during the ride
StreamSubscription<QuerySnapshot> driverStream;
// this stream is for all the driver on the app
StreamSubscription<List<DriverModel>> allDriversStream;
DriverModel driverModel;
LatLng pickupCoordinates;
LatLng destinationCoordinates;
double ridePrice = 0;
String notificationType = "";
AppStateProvider() {
_saveDeviceToken();
fcm.configure(
// this callback is used when the app runs on the foreground
onMessage: handleOnMessage,
// used when the app is closed completely and is launched using the notification
onLaunch: handleOnLaunch,
// when its on the background and opened using the notification drawer
onResume: handleOnResume);
_setCustomMapPin();
_getUserLocation();
_listemToDrivers();
Geolocator().getPositionStream().listen(_updatePosition);
}
// ANCHOR: MAPS & LOCATION METHODS
_updatePosition(Position newPosition){
position = newPosition;
notifyListeners();
}
Future<Position> _getUserLocation() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
position = await Geolocator().getCurrentPosition();
List<Placemark> placemark = await Geolocator()
.placemarkFromCoordinates(position.latitude, position.longitude);
if (prefs.getString(COUNTRY) == null) {
String country = placemark[0].isoCountryCode.toLowerCase();
await prefs.setString(COUNTRY, country);
}
_center = LatLng(position.latitude, position.longitude);
notifyListeners();
return position;
}
onCreate(GoogleMapController controller) {
_mapController = controller;
notifyListeners();
}
setLastPosition(LatLng position) {
_lastPosition = position;
notifyListeners();
}
onCameraMove(CameraPosition position) {
// MOVE the pickup marker only when selecting the pickup location
if (show == Show.PICKUP_SELECTION) {
_lastPosition = position.target;
changePickupLocationAddress(address: "loading...");
if (_markers.isNotEmpty) {
_markers.forEach((element) async {
if (element.markerId.value == PICKUP_MARKER_ID) {
_markers.remove(element);
pickupCoordinates = position.target;
addPickupMarker(position.target);
List<Placemark> placemark = await Geolocator()
.placemarkFromCoordinates(
position.target.latitude, position.target.longitude);
pickupLocationControlelr.text = placemark[0].name;
notifyListeners();
}
});
}
notifyListeners();
}
}
PUBSPEC.YAML
dependencies:
flutter:
sdk: flutter
cloud_firestore: any
cupertino_icons: any
firebase_auth: any
firebase_core: any
firebase_messaging: ^5.0.2
flutter_google_places: any
flutter_spinkit: ^4.1.2
geocoder: any
geoflutterfire: ^2.0.3+6
geolocator: any
get_it: ^1.0.3+2
google_maps_flutter: any
google_maps_webservice: any
http: any
location: any
modal_bottom_sheet: ^0.2.2
percent_indicator: ^2.1.7+2
provider: ^5.0.0
rxdart: any
shared_preferences: any
url_launcher: any
uuid: any
【问题讨论】:
标签: firebase flutter google-maps google-maps-api-3