I am trying to create a project on flutter using Geolocation plugin.
But 'result' variable of type Geolocation is not working fine. I am using getter 'isSuccessfull' of result type. It is throwing error displaying that no such getter exist.How can I get rid of this problem.Please help.
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
import 'package:geolocation/geolocation.dart';
void main() {
runApp(new MyCurrentLocationMap());
}
class MyCurrentLocationMap extends StatefulWidget {
@override
_MyCurrentLocationMapState createState() => _MyCurrentLocationMapState();
}
class _MyCurrentLocationMapState extends State<MyCurrentLocationMap> {
MapController mapController = new MapController();
getPermission() async {
final GeolocationResult result =
await Geolocation.requestLocationPermission(
permission: const LocationPermission(
android: LocationPermissionAndroid.fine,
ios: LocationPermissionIOS.always));
return result;
}
getLocation() {
return getPermission().then((result) {
if (result.isSuccessful) {
final coords =
Geolocation.currentLocation(accuracy: LocationAccuracy.best);
print(coords);
return coords;
}
});
}
dynamic lat, long;
buildMap() {
getLocation().then((response) {
if (response.isSuccessful) {
response.listen((value) {
mapController.move(
new LatLng(value.location.latitude, value.location.longitude),
15.0);
lat = value.location.latitude;
long = value.location.longitude;
});
}
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new FlutterMap(
mapController: mapController,
options: MapOptions(
minZoom: 100.0,
center: buildMap(),
),
layers: [
new TileLayerOptions(
urlTemplate:
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c']),
new MarkerLayerOptions(markers: [
new Marker(
width: 45.0,
height: 45.0,
point: new LatLng(lat, long),
builder: (context) => new Container(
child: IconButton(
icon: Icon(Icons.location_on),
color: Colors.blue,
iconSize: 45.0,
onPressed: () {
print("Market tapped");
},
),
))
])
],
),
),
);
}
}
pubspec.yaml
name: helloWorld
description: A new Flutter project.
publish_to: 'none'
CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_circular_chart:
flutter_map:
geolocation: ^1.0.0
cupertino_icons: ^0.1.3
http: ^0.12.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
fonts:
- family: bebas-neue
fonts:
- asset: assets/BebasNeue-Regular.ttf
The following link shows the error image
https://pasteboard.co/JLg7jra.png
question from:
https://stackoverflow.com/questions/65882947/geolocation-issuccessful-getter-showing-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…