File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed
packages/google_maps_flutter/google_maps_flutter Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -517,10 +517,12 @@ class _GoogleMapState extends State<GoogleMap> {
517
517
this ,
518
518
);
519
519
_controller.complete (controller);
520
- _updateTileOverlays (controller);
521
- final MapCreatedCallback ? onMapCreated = widget.onMapCreated;
522
- if (onMapCreated != null ) {
523
- onMapCreated (controller);
520
+ if (mounted) {
521
+ _updateTileOverlays (controller);
522
+ final MapCreatedCallback ? onMapCreated = widget.onMapCreated;
523
+ if (onMapCreated != null ) {
524
+ onMapCreated (controller);
525
+ }
524
526
}
525
527
}
526
528
Original file line number Diff line number Diff line change @@ -37,8 +37,17 @@ class FakeGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform {
37
37
final StreamController <MapEvent <dynamic >> mapEventStreamController =
38
38
StreamController <MapEvent <dynamic >>.broadcast ();
39
39
40
+ // Overrides completion of the init.
41
+ Completer <void >? initCompleter;
42
+
40
43
@override
41
- Future <void > init (int mapId) async {}
44
+ Future <void > init (int mapId) {
45
+ if (initCompleter == null ) {
46
+ return Future <void >.value ();
47
+ }
48
+
49
+ return initCompleter! .future;
50
+ }
42
51
43
52
@override
44
53
Future <void > updateMapConfiguration (
Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'dart:async' ;
6
+
5
7
import 'package:flutter/widgets.dart' ;
6
8
import 'package:flutter_test/flutter_test.dart' ;
7
9
import 'package:google_maps_flutter/google_maps_flutter.dart' ;
@@ -610,4 +612,28 @@ void main() {
610
612
611
613
expect (map.circleUpdates.length, 1 );
612
614
});
615
+
616
+ testWidgets ('Update state after map is initialized only when mounted' ,
617
+ (WidgetTester tester) async {
618
+ platform.initCompleter = Completer <void >();
619
+
620
+ await tester.pumpWidget (
621
+ const Directionality (
622
+ textDirection: TextDirection .ltr,
623
+ child: GoogleMap (
624
+ initialCameraPosition: CameraPosition (target: LatLng (10.0 , 15.0 )),
625
+ ),
626
+ ),
627
+ );
628
+
629
+ await tester.pumpWidget (Container ());
630
+
631
+ platform.initCompleter! .complete ();
632
+
633
+ await tester.pumpAndSettle ();
634
+
635
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
636
+
637
+ expect (map.tileOverlaySets.length, 1 );
638
+ });
613
639
}
You can’t perform that action at this time.
0 commit comments