Positioned(
bottom: 25,
right: 10,
child: FloatingActionButton(
heroTag: 'tag1',
backgroundColor: Colors.white.withOpacity(0.7),
child: Icon(
Icons.location_searching,
color: Colors.purple,
),
onPressed: () {
_addGeoPoint();
_animateToUser();
}),
),
仅_animateToUser正在工作
_animateToUser() async {
var pos = await location.getLocation();
mapController.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target: LatLng(pos.latitude, pos.longitude), zoom: 17.0)));
}
_ addGeoPoint不起作用
Future<DocumentReference> _addGeoPoint() async {
var pos = await location.getLocation();
final coordinates = Coordinates(pos.latitude, pos.longitude);
var addresses =
await Geocoder.local.findAddressesFromCoordinates(coordinates);
var first = addresses.first;
print("${first.featureName} : ${first.addressLine}");
// GeoFirePoint point =
// geo.point(latitude: pos.latitude, longitude: pos.longitude);
return _firestore.collection('location').add({
'UserLocation': first.featureName,
'UserLocationName': first.addressLine
});
}
但是当我更改onPressed为
onPressed: _addGeopoint,
_ addGeopoint起作用。
我无法一次调用这两个功能。
当您在函数中使用async并等待时,需要将try / catch并将return语句放入catch中。万一发生任何异常或由于其他一些原因而导致无法进一步处理,它将不会调用第二个函数。请检查以下示例是否相同。