Skip to content

Commit a2c1741

Browse files
authored
[google_maps_flutter] Use completer to get map id (#464)
* Map generation callback is an asynchronous call, so a completer is required. * This patch fixes test failures that occur on the device while testing. Signed-off-by: Boram Bae <[email protected]>
1 parent 5b23776 commit a2c1741

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

packages/google_maps_flutter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Fix integration test failures
4+
15
## 0.1.3
26

37
* Resolve linter warnings.

packages/google_maps_flutter/example/integration_test/google_maps_test.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void main() {
2222
testWidgets('updateMinMaxZoomLevels', (WidgetTester tester) async {
2323
final Key key = GlobalKey();
2424
late GoogleMapsPlugin plugin;
25-
int mapId = -1;
25+
final Completer<int> mapIdCompleter = Completer<int>();
2626

2727
const MinMaxZoomPreference initialZoomLevel = MinMaxZoomPreference(4, 8);
2828
const MinMaxZoomPreference finalZoomLevel = MinMaxZoomPreference(6, 10);
@@ -34,11 +34,11 @@ void main() {
3434
initialCameraPosition: _kInitialCameraPosition,
3535
minMaxZoomPreference: initialZoomLevel,
3636
onMapCreated: (GoogleMapController c) {
37-
mapId = c.mapId;
37+
mapIdCompleter.complete(c.mapId);
3838
},
3939
),
4040
));
41-
41+
final int mapId = await mapIdCompleter.future;
4242
await tester.pumpAndSettle();
4343
await tester.pumpAndSettle(const Duration(seconds: 3));
4444

@@ -68,7 +68,7 @@ void main() {
6868
testWidgets('testZoomGesturesEnabled', (WidgetTester tester) async {
6969
final Key key = GlobalKey();
7070
late GoogleMapsPlugin plugin;
71-
int mapId = -1;
71+
final Completer<int> mapIdCompleter = Completer<int>();
7272

7373
await tester.pumpWidget(Directionality(
7474
textDirection: TextDirection.ltr,
@@ -77,11 +77,11 @@ void main() {
7777
initialCameraPosition: _kInitialCameraPosition,
7878
zoomGesturesEnabled: false,
7979
onMapCreated: (GoogleMapController c) {
80-
mapId = c.mapId;
80+
mapIdCompleter.complete(c.mapId);
8181
},
8282
),
8383
));
84-
84+
final int mapId = await mapIdCompleter.future;
8585
await tester.pumpAndSettle();
8686
await tester.pumpAndSettle(const Duration(seconds: 3));
8787

@@ -110,19 +110,19 @@ void main() {
110110
testWidgets('testZoomControlsEnabled', (WidgetTester tester) async {
111111
final Key key = GlobalKey();
112112
late GoogleMapsPlugin plugin;
113-
int mapId = -1;
113+
final Completer<int> mapIdCompleter = Completer<int>();
114114

115115
await tester.pumpWidget(Directionality(
116116
textDirection: TextDirection.ltr,
117117
child: GoogleMap(
118118
key: key,
119119
initialCameraPosition: _kInitialCameraPosition,
120120
onMapCreated: (GoogleMapController c) {
121-
mapId = c.mapId;
121+
mapIdCompleter.complete(c.mapId);
122122
},
123123
),
124124
));
125-
125+
final int mapId = await mapIdCompleter.future;
126126
await tester.pumpAndSettle();
127127
await tester.pumpAndSettle(const Duration(seconds: 2));
128128

@@ -152,7 +152,7 @@ void main() {
152152
testWidgets('testScrollGesturesEnabled', (WidgetTester tester) async {
153153
final Key key = GlobalKey();
154154
late GoogleMapsPlugin plugin;
155-
int mapId = -1;
155+
final Completer<int> mapIdCompleter = Completer<int>();
156156

157157
await tester.pumpWidget(Directionality(
158158
textDirection: TextDirection.ltr,
@@ -161,11 +161,11 @@ void main() {
161161
initialCameraPosition: _kInitialCameraPosition,
162162
scrollGesturesEnabled: false,
163163
onMapCreated: (GoogleMapController c) {
164-
mapId = c.mapId;
164+
mapIdCompleter.complete(c.mapId);
165165
},
166166
),
167167
));
168-
168+
final int mapId = await mapIdCompleter.future;
169169
await tester.pumpAndSettle();
170170
await tester.pumpAndSettle(const Duration(seconds: 3));
171171

@@ -302,7 +302,7 @@ void main() {
302302
testWidgets('testTraffic', (WidgetTester tester) async {
303303
final Key key = GlobalKey();
304304
late GoogleMapsPlugin plugin;
305-
int mapId = -1;
305+
final Completer<int> mapIdCompleter = Completer<int>();
306306

307307
await tester.pumpWidget(Directionality(
308308
textDirection: TextDirection.ltr,
@@ -311,11 +311,11 @@ void main() {
311311
initialCameraPosition: _kInitialCameraPosition,
312312
trafficEnabled: true,
313313
onMapCreated: (GoogleMapController c) {
314-
mapId = c.mapId;
314+
mapIdCompleter.complete(c.mapId);
315315
},
316316
),
317317
));
318-
318+
final int mapId = await mapIdCompleter.future;
319319
await tester.pumpAndSettle();
320320
await tester.pumpAndSettle(const Duration(seconds: 3));
321321

0 commit comments

Comments
 (0)