Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add clearMarkers() functionality to GoogleMapController #843

Merged
merged 7 commits into from
Oct 12, 2018

Conversation

kenzieschmoll
Copy link
Member

Add a method to clear all the markers currently on the map. There is currently a method to add, update, and remove a single marker, but not a method to remove all markers.

Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

LGTM with one nit

Future<void> clearMarkers() async {
assert(_markers != null);
await _markers.forEach((String id, Marker marker) async {
await _channel.invokeMethod('marker#remove', <String, dynamic>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be nice to extract the common part for this and removeMarker to a private method (mainly so we have a single copy of 'marker#remove' in the dart code)

…d by controller#removeMarker and controller#clearMarkers.
assert(_markers != null);
_markers.forEach((String id, Marker marker) async {
await _removeMarker(id);
_markers.remove(id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this can be moved into _removeMarker

notifyListeners();
}

void _removeMarker(String id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should return a Future so we can await it

/// The returned [Future] completes once listeners have been notified.
Future<void> clearMarkers() async {
assert(_markers != null);
_markers.forEach((String id, Marker marker) async {
Copy link
Contributor

@amirh amirh Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that nothing awaits the closure passed to forEach, so the notifyListeners will happen immediately and the clearMarkers method will complete immediately...

@kenzieschmoll kenzieschmoll merged commit ab6d93d into flutter:master Oct 12, 2018
@kenzieschmoll kenzieschmoll deleted the clear_markers branch October 12, 2018 22:03
andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
Add clearMarkers() functionality to GoogleMapController. This method will clear all markers currently present on the map.
andreidiaconu added a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants