一个颤振小部件具有GPS坐标 我需要将坐标传递到另一个小部件。
这是currentLocation小部件类。我需要另一个小部件中的long lat值。
_initCurrentLocation() {
Geolocator()
..forceAndroidLocationManager = !widget.androidFusedLocation
..getCurrentPosition(
desiredAccuracy: LocationAccuracy.best,
).then((position) {
if (mounted) {
setState(() => _currentPosition = position);
}
}).catchError((e) {
//
});
}
@override
Widget build(BuildContext context) {
return FutureBuilder<GeolocationStatus>(
future: Geolocator().checkGeolocationPermissionStatus(),
builder:
(BuildContext context, AsyncSnapshot<GeolocationStatus> snapshot) {
if (!snapshot.hasData) {
return const Center(child: CircularProgressIndicator());
}
return Text('${_currentPosition.latitude} ${_currentPosition.longitude}'),
这是另一个小部件。此小部件的功能需要很长和很长时间才能进行API调用。
Future loadWeather() async {
setState(() {
isLoading = true;
});
// final lat = //get the value from other widget;
// final lon = //get the value from other widget
final weatherResponse = await http.get(
'https://api.openweathermap.org/data/2.5/weather?APPID=${openWeatherToken}&lat=${lat.toString()}&lon=${lon.toString()}');