buildViewWithConfiguration method
Widget
buildViewWithConfiguration(
- int creationId,
- PlatformViewCreatedCallback onPlatformViewCreated, {
- required MapWidgetConfiguration widgetConfiguration,
- MapObjects mapObjects = const MapObjects(),
- MapConfiguration mapConfiguration = const MapConfiguration(),
Returns a widget displaying the map view.
Implementation
@override
Widget buildViewWithConfiguration(
int creationId,
PlatformViewCreatedCallback onPlatformViewCreated, {
required MapWidgetConfiguration widgetConfiguration,
MapObjects mapObjects = const MapObjects(),
MapConfiguration mapConfiguration = const MapConfiguration(),
}) {
// Bail fast if we've already rendered this map ID...
if (_mapById[creationId]?.widget != null) {
return _mapById[creationId]!.widget!;
}
final controller = StreamController<MapEvent<Object?>>.broadcast();
final mapController = GoogleMapController(
mapId: creationId,
streamController: controller,
widgetConfiguration: widgetConfiguration,
mapObjects: mapObjects,
mapConfiguration: mapConfiguration,
)..init(); // Initialize the controller
_mapById[creationId] = mapController;
mapController.events.whereType<WebMapReadyEvent>().first.then((
WebMapReadyEvent event,
) {
assert(
creationId == event.mapId,
'Received WebMapReadyEvent for the wrong map',
);
// Notify the plugin now that there's a fully initialized controller.
onPlatformViewCreated.call(event.mapId);
});
assert(
mapController.widget != null,
'The widget of a GoogleMapController cannot be null before calling dispose on it.',
);
return mapController.widget!;
}