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

Commit

Permalink
Fix issue where markers aren't updated in Flutter v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia committed May 19, 2022
1 parent f33222a commit 13a2e04
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.1.6

* Fixes issue in Flutter v3.0.0 where markers aren't updated.
* Fixes iOS native unit tests on M1 devices.
* Minor fixes for new analysis options.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import android.view.Choreographer;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -151,6 +152,17 @@ public void onMapReady(GoogleMap googleMap) {
updateInitialTileOverlays();
}

private static void postFrameCallback(Runnable f) {
Choreographer.getInstance().postFrameCallback(
new Choreographer.FrameCallback() {
@Override
public void doFrame(long frameTimeNanos) {
f.run();
}
}
);
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
switch (call.method) {
Expand Down Expand Up @@ -250,6 +262,27 @@ public void onSnapshotReady(Bitmap bitmap) {
markersController.changeMarkers(markersToChange);
List<Object> markerIdsToRemove = call.argument("markerIdsToRemove");
markersController.removeMarkers(markerIdsToRemove);

// gmscore GL renderer uses a TextureView.
// Android platform views that are displayed as a texture after Flutter v3.0.0.
// require that the view hierarchy is notified after all drawing operations have been flushed.
// Since the GL renderer doesn't use standard Android views, and instead uses GL directly,
// we notify the view hierarchy by invalidating the view.
// Unfortunately, when OnMapLoadedCallback is fired, the texture may not have been updated yet.
// To workaround this limitation, wait two frames.
// This ensures that at least the frame budget (16.66ms at 60hz) have passed since the
// drawing operation was issued.
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
postFrameCallback(() -> {
postFrameCallback(() -> {
mapView.invalidate();
});
});
}
});

result.success(null);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_flutter/google_maps_flutter
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.1.5
version: 2.1.6

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down

0 comments on commit 13a2e04

Please sign in to comment.