我正在尝试在对话框中显示Google地图,第一次按预期弹出,但是第二次它抛出并异常:状态错误(错误状态:未来已经完成(。
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
},
),
),
],
),
这是一个总结发生的事情的 gif
我使用rflutter_alert: ^1.0.3作为对话框, 和google_maps_flutter:^0.5.21+15用于地图。
提前感谢!
这验证了以前我是否已经调用了"完成器(("如果是这样,则无需再次调用"完成器((",只需在代码中跳过它即可
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()
}
}
我认为问题是因为您尝试完成两次不允许的Completer
。我所做的是每次打电话给_displayDialog()
时创建一个新Completer
。
_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
},
),
),
],
),