Skip to content

Commit 8f417df

Browse files
committed
separate info window visibility check and small iOS logic fixes
1 parent 8ada4c6 commit 8f417df

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/integration_test/google_maps_test.dart

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,43 @@ void main() {
807807
});
808808

809809
testWidgets('testToggleInfoWindow', (WidgetTester tester) async {
810+
const Marker marker = Marker(
811+
markerId: MarkerId('marker'),
812+
infoWindow: InfoWindow(title: 'InfoWindow'));
813+
final Set<Marker> markers = <Marker>{marker};
814+
815+
final Completer<ExampleGoogleMapController> controllerCompleter =
816+
Completer<ExampleGoogleMapController>();
817+
818+
await tester.pumpWidget(Directionality(
819+
textDirection: TextDirection.ltr,
820+
child: ExampleGoogleMap(
821+
initialCameraPosition: const CameraPosition(target: LatLng(10.0, 15.0)),
822+
markers: markers,
823+
onMapCreated: (ExampleGoogleMapController googleMapController) {
824+
controllerCompleter.complete(googleMapController);
825+
},
826+
),
827+
));
828+
829+
final ExampleGoogleMapController controller =
830+
await controllerCompleter.future;
831+
832+
bool iwVisibleStatus =
833+
await controller.isMarkerInfoWindowShown(marker.markerId);
834+
expect(iwVisibleStatus, false);
835+
836+
await controller.showMarkerInfoWindow(marker.markerId);
837+
iwVisibleStatus = await controller.isMarkerInfoWindowShown(marker.markerId);
838+
expect(iwVisibleStatus, true);
839+
840+
await controller.hideMarkerInfoWindow(marker.markerId);
841+
iwVisibleStatus = await controller.isMarkerInfoWindowShown(marker.markerId);
842+
expect(iwVisibleStatus, false);
843+
});
844+
845+
testWidgets('updating a marker does not hide its info window',
846+
(WidgetTester tester) async {
810847
final Key key = GlobalKey();
811848
const Marker marker = Marker(
812849
markerId: MarkerId('marker'),
@@ -838,15 +875,13 @@ void main() {
838875
final ExampleGoogleMapController controller =
839876
await controllerCompleter.future;
840877

878+
await controller.showMarkerInfoWindow(marker.markerId);
841879
bool iwVisibleStatus =
842880
await controller.isMarkerInfoWindowShown(marker.markerId);
843-
expect(iwVisibleStatus, false);
844-
845-
await controller.showMarkerInfoWindow(marker.markerId);
846-
iwVisibleStatus = await controller.isMarkerInfoWindowShown(marker.markerId);
847881
expect(iwVisibleStatus, true);
848882

849-
// Update marker and check if the info window is still visible.
883+
// Update marker and ensure the info window remains visible when added to a
884+
// cluster manager.
850885
final Marker updatedMarker = marker.copyWith(
851886
alphaParam: 0.5,
852887
clusterManagerIdParam: clusterManager.clusterManagerId,
@@ -862,13 +897,8 @@ void main() {
862897
markers: Set<Marker>.of(markers)),
863898
));
864899

865-
await controller.showMarkerInfoWindow(marker.markerId);
866900
iwVisibleStatus = await controller.isMarkerInfoWindowShown(marker.markerId);
867901
expect(iwVisibleStatus, true);
868-
869-
await controller.hideMarkerInfoWindow(marker.markerId);
870-
iwVisibleStatus = await controller.isMarkerInfoWindowShown(marker.markerId);
871-
expect(iwVisibleStatus, false);
872902
});
873903

874904
testWidgets('testTakeSnapshot', (WidgetTester tester) async {

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ - (void)updateFromPlatformMarker:(FGMPlatformMarker *)platformMarker
128128
[self setInfoWindowTitle:infoWindow.title snippet:infoWindow.snippet];
129129
}
130130

131-
[self setVisible:platformMarker.visible];
132-
133131
// Set the marker's user data with current identifiers.
134132
FGMSetIdentifiersToMarkerUserData(self.markerIdentifier, self.clusterManagerIdentifier,
135133
self.marker);
134+
135+
// Ensure setVisible is called last as it adds the marker to the map,
136+
// and must be done after all other parameters are set.
137+
[self setVisible:platformMarker.visible];
136138
}
137139

138140
@end
@@ -215,7 +217,7 @@ - (void)changeMarker:(FGMPlatformMarker *)markerToChange {
215217

216218
if ([controller.marker conformsToProtocol:@protocol(GMUClusterItem)]) {
217219
if (previousClusterManagerIdentifier &&
218-
![previousClusterManagerIdentifier isEqualToString:clusterManagerIdentifier]) {
220+
![clusterManagerIdentifier isEqualToString:previousClusterManagerIdentifier]) {
219221
// Remove marker from previous cluster manager if its cluster manager identifier is removed or
220222
// changed.
221223
GMUClusterManager *clusterManager = [_clusterManagersController

0 commit comments

Comments
 (0)