attach method

void attach(
  1. GoogleMapController platformController
)

Binds the GoogleMapController handed out by GoogleMap.onMapCreated.

onMapCreated fires once per platform view, not once per GoogleMapsController: the GoogleMap widget can be remounted — and its native map recreated — while the state that owns this controller lives on. So this has to cope with being called more than once.

The first call completes controller. Later calls swap in a fresh completer: the previous platform controller belongs to a GoogleMap that is no longer mounted, and every method on it throws a use-after-dispose StateError, so callers have to be handed the live one instead.

Implementation

void attach(GoogleMapController platformController) {
  if (_disposed) return;
  _platformController = platformController;
  if (_mapController.isCompleted) {
    _mapController = Completer<GoogleMapController>();
  }
  _mapController.complete(platformController);
}