Skip to content

Commit 2ce59f0

Browse files
committed
Single retrieval of controller
1 parent 3fb0c81 commit 2ce59f0

File tree

1 file changed

+30
-55
lines changed

1 file changed

+30
-55
lines changed

packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -429,96 +429,75 @@ class _GoogleMapState extends State<GoogleMap> {
429429
@override
430430
void didUpdateWidget(GoogleMap oldWidget) {
431431
super.didUpdateWidget(oldWidget);
432-
_updateOptions();
433-
_updateClusterManagers();
434-
_updateMarkers();
435-
_updatePolygons();
436-
_updatePolylines();
437-
_updateCircles();
438-
_updateHeatmaps();
439-
_updateTileOverlays();
440-
_updateGroundOverlays();
432+
433+
_refreshStateFromWidget();
434+
}
435+
436+
Future<void> _refreshStateFromWidget() async {
437+
final GoogleMapController controller = await _controller.future;
438+
if (!mounted) {
439+
return;
440+
}
441+
442+
_updateOptions(controller);
443+
_updateClusterManagers(controller);
444+
_updateMarkers(controller);
445+
_updatePolygons(controller);
446+
_updatePolylines(controller);
447+
_updateCircles(controller);
448+
_updateHeatmaps(controller);
449+
_updateTileOverlays(controller);
450+
_updateGroundOverlays(controller);
441451
}
442452

443-
Future<void> _updateOptions() async {
453+
void _updateOptions(GoogleMapController controller) {
444454
final MapConfiguration newConfig = _configurationFromMapWidget(widget);
445455
final MapConfiguration updates = newConfig.diffFrom(_mapConfiguration);
446456
if (updates.isEmpty) {
447457
return;
448458
}
449-
final GoogleMapController controller = await _controller.future;
450-
if (!mounted) {
451-
return;
452-
}
459+
453460
unawaited(controller._updateMapConfiguration(updates));
454461
_mapConfiguration = newConfig;
455462
}
456463

457-
Future<void> _updateMarkers() async {
458-
final GoogleMapController controller = await _controller.future;
459-
if (!mounted) {
460-
return;
461-
}
464+
void _updateMarkers(GoogleMapController controller) {
462465
unawaited(controller._updateMarkers(
463466
MarkerUpdates.from(_markers.values.toSet(), widget.markers)));
464467
_markers = keyByMarkerId(widget.markers);
465468
}
466469

467-
Future<void> _updateClusterManagers() async {
468-
final GoogleMapController controller = await _controller.future;
469-
if (!mounted) {
470-
return;
471-
}
470+
void _updateClusterManagers(GoogleMapController controller) {
472471
unawaited(controller._updateClusterManagers(ClusterManagerUpdates.from(
473472
_clusterManagers.values.toSet(), widget.clusterManagers)));
474473
_clusterManagers = keyByClusterManagerId(widget.clusterManagers);
475474
}
476475

477-
Future<void> _updateGroundOverlays() async {
478-
final GoogleMapController controller = await _controller.future;
479-
if (!mounted) {
480-
return;
481-
}
476+
void _updateGroundOverlays(GoogleMapController controller) {
482477
unawaited(controller._updateGroundOverlays(GroundOverlayUpdates.from(
483478
_groundOverlays.values.toSet(), widget.groundOverlays)));
484479
_groundOverlays = keyByGroundOverlayId(widget.groundOverlays);
485480
}
486481

487-
Future<void> _updatePolygons() async {
488-
final GoogleMapController controller = await _controller.future;
489-
if (!mounted) {
490-
return;
491-
}
482+
void _updatePolygons(GoogleMapController controller) {
492483
unawaited(controller._updatePolygons(
493484
PolygonUpdates.from(_polygons.values.toSet(), widget.polygons)));
494485
_polygons = keyByPolygonId(widget.polygons);
495486
}
496487

497-
Future<void> _updatePolylines() async {
498-
final GoogleMapController controller = await _controller.future;
499-
if (!mounted) {
500-
return;
501-
}
488+
void _updatePolylines(GoogleMapController controller) {
502489
unawaited(controller._updatePolylines(
503490
PolylineUpdates.from(_polylines.values.toSet(), widget.polylines)));
504491
_polylines = keyByPolylineId(widget.polylines);
505492
}
506493

507-
Future<void> _updateCircles() async {
508-
final GoogleMapController controller = await _controller.future;
509-
if (!mounted) {
510-
return;
511-
}
494+
void _updateCircles(GoogleMapController controller) {
512495
unawaited(controller._updateCircles(
513496
CircleUpdates.from(_circles.values.toSet(), widget.circles)));
514497
_circles = keyByCircleId(widget.circles);
515498
}
516499

517-
Future<void> _updateHeatmaps() async {
518-
final GoogleMapController controller = await _controller.future;
519-
if (!mounted) {
520-
return;
521-
}
500+
void _updateHeatmaps(GoogleMapController controller) {
522501
unawaited(
523502
controller._updateHeatmaps(
524503
HeatmapUpdates.from(_heatmaps.values.toSet(), widget.heatmaps),
@@ -527,11 +506,7 @@ class _GoogleMapState extends State<GoogleMap> {
527506
_heatmaps = keyByHeatmapId(widget.heatmaps);
528507
}
529508

530-
Future<void> _updateTileOverlays() async {
531-
final GoogleMapController controller = await _controller.future;
532-
if (!mounted) {
533-
return;
534-
}
509+
void _updateTileOverlays(GoogleMapController controller) {
535510
unawaited(controller._updateTileOverlays(widget.tileOverlays));
536511
}
537512

@@ -542,7 +517,7 @@ class _GoogleMapState extends State<GoogleMap> {
542517
this,
543518
);
544519
_controller.complete(controller);
545-
unawaited(_updateTileOverlays());
520+
_updateTileOverlays(controller);
546521
final MapCreatedCallback? onMapCreated = widget.onMapCreated;
547522
if (onMapCreated != null) {
548523
onMapCreated(controller);

0 commit comments

Comments
 (0)