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

Commit b5683f1

Browse files
author
Emmanuel Garcia
committed
Fix issue where markers aren't updated in Flutter v3.0.0
1 parent f33222a commit b5683f1

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.1.6
22

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

packages/google_maps_flutter/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.graphics.Point;
1313
import android.os.Bundle;
1414
import android.util.Log;
15+
import android.view.Choreographer;
1516
import android.view.View;
1617
import androidx.annotation.NonNull;
1718
import androidx.annotation.Nullable;
@@ -151,6 +152,17 @@ public void onMapReady(GoogleMap googleMap) {
151152
updateInitialTileOverlays();
152153
}
153154

155+
private static void postFrameCallback(Runnable f) {
156+
Choreographer.getInstance().postFrameCallback(
157+
new Choreographer.FrameCallback() {
158+
@Override
159+
public void doFrame(long frameTimeNanos) {
160+
f.run();
161+
}
162+
}
163+
);
164+
}
165+
154166
@Override
155167
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
156168
switch (call.method) {
@@ -250,6 +262,27 @@ public void onSnapshotReady(Bitmap bitmap) {
250262
markersController.changeMarkers(markersToChange);
251263
List<Object> markerIdsToRemove = call.argument("markerIdsToRemove");
252264
markersController.removeMarkers(markerIdsToRemove);
265+
266+
// gmscore GL renderer uses a TextureView.
267+
// Android platform views that are displayed as a texture after Flutter v3.0.0.
268+
// require that the view hierarchy is notified after all drawing operations have been flushed.
269+
// Since the GL renderer doesn't use standard Android views, and instead uses TextureView,
270+
// we notify the view hierarchy by invalidating the view.
271+
// Unfortunately, when OnMapLoadedCallback is fired, the texture may not have been updated yet.
272+
// To workaround this limitation, wait two frames.
273+
// This ensures that at least the frame budget (16.66ms at 60hz) have passed since the
274+
// drawing operation was issued.
275+
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
276+
@Override
277+
public void onMapLoaded() {
278+
postFrameCallback(() -> {
279+
postFrameCallback(() -> {
280+
mapView.invalidate();
281+
});
282+
});
283+
}
284+
});
285+
253286
result.success(null);
254287
break;
255288
}

packages/google_maps_flutter/google_maps_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter
22
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
33
repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_flutter/google_maps_flutter
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 2.1.5
5+
version: 2.1.6
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

0 commit comments

Comments
 (0)