Flutter: Google Maps StateError (Bad state: Future already completed) Flutter: Google Maps StateError (Bad state: Future already completed) dart dart

Flutter: Google Maps StateError (Bad state: Future already completed)


I think that the problem is because you are trying to complete a Completer twice which is not allowed. What I did bellow was to create a new Completer each time you call _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            },          ),        ),            ],    ),


this verifies if previously I already called "completer ()" if so, you don't need to call "completer ()" again, and just skip it in your code

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()    }}