@@ -20,7 +20,8 @@ void main() {
20
20
setUp (() {
21
21
// Use a mock platform so we never need to hit the MethodChannel code.
22
22
GoogleMapsFlutterPlatform .instance = platform;
23
- when (platform.buildView (any, any, any)).thenReturn (Container ());
23
+ resetMockitoState ();
24
+ _setupMock (platform);
24
25
});
25
26
26
27
testWidgets ('_webOnlyMapCreationId increments with each GoogleMap widget' , (
@@ -61,4 +62,60 @@ void main() {
61
62
),
62
63
]);
63
64
});
65
+
66
+ testWidgets ('Calls platform.dispose when GoogleMap is disposed of' , (
67
+ WidgetTester tester,
68
+ ) async {
69
+ await tester.pumpWidget (GoogleMap (
70
+ initialCameraPosition: CameraPosition (
71
+ target: LatLng (43.3608 , - 5.8702 ),
72
+ ),
73
+ ));
74
+
75
+ // Now dispose of the map...
76
+ await tester.pumpWidget (Container ());
77
+
78
+ verify (platform.dispose (mapId: anyNamed ('mapId' )));
79
+ });
80
+ }
81
+
82
+ // Some test setup classes below...
83
+
84
+ class _MockStream <T > extends Mock implements Stream <T > {}
85
+
86
+ typedef _CreationCallback = void Function (int );
87
+
88
+ // Installs test mocks on the platform
89
+ void _setupMock (MockGoogleMapsFlutterPlatform platform) {
90
+ // Used to create the view of the map...
91
+ when (platform.buildView (any, any, any)).thenAnswer ((realInvocation) {
92
+ // Call the onPlatformViewCreated callback so the controller gets created.
93
+ _CreationCallback onPlatformViewCreatedCb =
94
+ realInvocation.positionalArguments[2 ];
95
+ onPlatformViewCreatedCb.call (0 );
96
+ return Container ();
97
+ });
98
+ // Used to create the Controller
99
+ when (platform.onCameraIdle (mapId: anyNamed ('mapId' )))
100
+ .thenAnswer ((_) => _MockStream <CameraIdleEvent >());
101
+ when (platform.onCameraMove (mapId: anyNamed ('mapId' )))
102
+ .thenAnswer ((_) => _MockStream <CameraMoveEvent >());
103
+ when (platform.onCameraMoveStarted (mapId: anyNamed ('mapId' )))
104
+ .thenAnswer ((_) => _MockStream <CameraMoveStartedEvent >());
105
+ when (platform.onCircleTap (mapId: anyNamed ('mapId' )))
106
+ .thenAnswer ((_) => _MockStream <CircleTapEvent >());
107
+ when (platform.onInfoWindowTap (mapId: anyNamed ('mapId' )))
108
+ .thenAnswer ((_) => _MockStream <InfoWindowTapEvent >());
109
+ when (platform.onLongPress (mapId: anyNamed ('mapId' )))
110
+ .thenAnswer ((_) => _MockStream <MapLongPressEvent >());
111
+ when (platform.onMarkerDragEnd (mapId: anyNamed ('mapId' )))
112
+ .thenAnswer ((_) => _MockStream <MarkerDragEndEvent >());
113
+ when (platform.onMarkerTap (mapId: anyNamed ('mapId' )))
114
+ .thenAnswer ((_) => _MockStream <MarkerTapEvent >());
115
+ when (platform.onPolygonTap (mapId: anyNamed ('mapId' )))
116
+ .thenAnswer ((_) => _MockStream <PolygonTapEvent >());
117
+ when (platform.onPolylineTap (mapId: anyNamed ('mapId' )))
118
+ .thenAnswer ((_) => _MockStream <PolylineTapEvent >());
119
+ when (platform.onTap (mapId: anyNamed ('mapId' )))
120
+ .thenAnswer ((_) => _MockStream <MapTapEvent >());
64
121
}
0 commit comments