lor*_*ncm 4 google-maps exception dart flutter
我试图在对话框中显示谷歌地图,第一次它按预期弹出,但是第二次它抛出异常:StateError(错误状态:未来已经完成)。
Completer<GoogleMapController> _controller = Completer();
_displayDialog(){
Alert(
context: context,
style: alertStyle,
title: "Here are your results:",
content: Column(
children: <Widget>[
Container(
width: 200.0,
height: 200.0,
child: GoogleMap(
//mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller); //throws here in this line
},
),
),
],
),
Run Code Online (Sandbox Code Playgroud)
我在对话框中使用rflutter_alert: ^1.0.3,在地图中使用google_maps_flutter: ^0.5.21+15。
提前致谢!
小智 18
这将验证之前我是否已经调用过“completer()”,如果是的话,您不需要再次调用“completer()”,只需在代码中跳过它
onMapCreated: (GoogleMapController controller) {
if (!_controller.isCompleted) {
//first calling is false
//call "completer()"
_controller.complete(controller);
}else{
//other calling, later is true,
//don't call again completer()
}
}
Run Code Online (Sandbox Code Playgroud)
我认为问题是因为您试图完成Completer两次这是不允许的。我所做的是在Completer每次调用时创建一个新的_displayDialog()。
_displayDialog(){
Completer<GoogleMapController> _controller = Completer();
Alert(
context: context,
style: alertStyle,
title: "Here are your results:",
content: Column(
children: <Widget>[
Container(
width: 200.0,
height: 200.0,
child: GoogleMap(
//mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller); //throws here in this line
},
),
),
],
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1823 次 |
| 最近记录: |