From 6a602e1100b4b9dd7310c19d0515f862a6815b1a Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Thu, 13 Oct 2022 15:05:16 +0900 Subject: [PATCH] [google_maps_flutter] Use completer to get map id * Map generation callback is an asynchronous call, so a completeer is required. * This patch fixes test failures that occur on the device while testing. Signed-off-by: Boram Bae --- packages/google_maps_flutter/CHANGELOG.md | 4 +++ .../integration_test/google_maps_test.dart | 30 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index 804d02390..a2c5c12c7 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Fix integration test failures + ## 0.1.3 * Resolve linter warnings. diff --git a/packages/google_maps_flutter/example/integration_test/google_maps_test.dart b/packages/google_maps_flutter/example/integration_test/google_maps_test.dart index 63132a25c..efbe7d850 100644 --- a/packages/google_maps_flutter/example/integration_test/google_maps_test.dart +++ b/packages/google_maps_flutter/example/integration_test/google_maps_test.dart @@ -22,7 +22,7 @@ void main() { testWidgets('updateMinMaxZoomLevels', (WidgetTester tester) async { final Key key = GlobalKey(); late GoogleMapsPlugin plugin; - int mapId = -1; + final Completer mapIdCompleter = Completer(); const MinMaxZoomPreference initialZoomLevel = MinMaxZoomPreference(4, 8); const MinMaxZoomPreference finalZoomLevel = MinMaxZoomPreference(6, 10); @@ -34,11 +34,11 @@ void main() { initialCameraPosition: _kInitialCameraPosition, minMaxZoomPreference: initialZoomLevel, onMapCreated: (GoogleMapController c) { - mapId = c.mapId; + mapIdCompleter.complete(c.mapId); }, ), )); - + final int mapId = await mapIdCompleter.future; await tester.pumpAndSettle(); await tester.pumpAndSettle(const Duration(seconds: 3)); @@ -68,7 +68,7 @@ void main() { testWidgets('testZoomGesturesEnabled', (WidgetTester tester) async { final Key key = GlobalKey(); late GoogleMapsPlugin plugin; - int mapId = -1; + final Completer mapIdCompleter = Completer(); await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, @@ -77,11 +77,11 @@ void main() { initialCameraPosition: _kInitialCameraPosition, zoomGesturesEnabled: false, onMapCreated: (GoogleMapController c) { - mapId = c.mapId; + mapIdCompleter.complete(c.mapId); }, ), )); - + final int mapId = await mapIdCompleter.future; await tester.pumpAndSettle(); await tester.pumpAndSettle(const Duration(seconds: 3)); @@ -110,7 +110,7 @@ void main() { testWidgets('testZoomControlsEnabled', (WidgetTester tester) async { final Key key = GlobalKey(); late GoogleMapsPlugin plugin; - int mapId = -1; + final Completer mapIdCompleter = Completer(); await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, @@ -118,11 +118,11 @@ void main() { key: key, initialCameraPosition: _kInitialCameraPosition, onMapCreated: (GoogleMapController c) { - mapId = c.mapId; + mapIdCompleter.complete(c.mapId); }, ), )); - + final int mapId = await mapIdCompleter.future; await tester.pumpAndSettle(); await tester.pumpAndSettle(const Duration(seconds: 2)); @@ -152,7 +152,7 @@ void main() { testWidgets('testScrollGesturesEnabled', (WidgetTester tester) async { final Key key = GlobalKey(); late GoogleMapsPlugin plugin; - int mapId = -1; + final Completer mapIdCompleter = Completer(); await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, @@ -161,11 +161,11 @@ void main() { initialCameraPosition: _kInitialCameraPosition, scrollGesturesEnabled: false, onMapCreated: (GoogleMapController c) { - mapId = c.mapId; + mapIdCompleter.complete(c.mapId); }, ), )); - + final int mapId = await mapIdCompleter.future; await tester.pumpAndSettle(); await tester.pumpAndSettle(const Duration(seconds: 3)); @@ -302,7 +302,7 @@ void main() { testWidgets('testTraffic', (WidgetTester tester) async { final Key key = GlobalKey(); late GoogleMapsPlugin plugin; - int mapId = -1; + final Completer mapIdCompleter = Completer(); await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, @@ -311,11 +311,11 @@ void main() { initialCameraPosition: _kInitialCameraPosition, trafficEnabled: true, onMapCreated: (GoogleMapController c) { - mapId = c.mapId; + mapIdCompleter.complete(c.mapId); }, ), )); - + final int mapId = await mapIdCompleter.future; await tester.pumpAndSettle(); await tester.pumpAndSettle(const Duration(seconds: 3));