【发布时间】:2021-03-28 17:24:24
【问题描述】:
void getLocation() async {
await location.getCurrentLocation();
*latlng* = LatLng(location.latitude, location.longitude);}
。 .
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
GoogleMap(
onMapCreated: _onMapCreated,
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
target: *latlng*,
zoom: 14.4746,
),
),
我想在小部件中使用 latlng。但是,'target == null' 是异步输出的。我该怎么办?
【问题讨论】:
-
欢迎来到 Stackoverflow。如果您没有得到答案,这通常是因为您没有以非常清晰和详细的方式提问。请添加更多信息,然后您将产生更好的影响。
-
使用 if else,检查 latlng 是否为空,然后显示加载器,直到 latlng 接收到 latlng 后将其传递给 map
标签: flutter asynchronous dart async-await future