attach method

void attach(
  1. MapboxMap map
)

Binds the MapboxMap handed out by MapWidget.onMapCreated.

onMapCreated fires once per platform view, and the view can be recreated while this controller lives on, so completing the future directly throws Bad state: Future already completed the second time round. Later calls swap in a fresh completer, handing new callers the live map instead of the destroyed one.

Implementation

void attach(MapboxMap map) {
  if (_disposed) return;
  if (_mapController.isCompleted) {
    _mapController = Completer<MapboxMap>();
  }
  _mapController.complete(map);
}