Skip to content

Commit a9aa15e

Browse files
authored
Merge pull request #10 from filiph/fix/dispose-controller
Handle disposed map correctly
2 parents fe6d442 + 6c027c1 commit a9aa15e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/samples/camera_animate.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class _AnimateCameraSampleState extends State<AnimateCameraSample> {
4747
);
4848
}
4949

50+
@override
51+
void dispose() {
52+
_controller = null;
53+
super.dispose();
54+
}
55+
5056
/// Called when the button is pressed.
5157
void _onPressed() {
5258
// Set up the desired camera update.

lib/samples/camera_move.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class _MoveCameraSampleState extends State<MoveCameraSample> {
4747
);
4848
}
4949

50+
@override
51+
void dispose() {
52+
_controller = null;
53+
super.dispose();
54+
}
55+
5056
/// Called when the button is pressed.
5157
void _onPressed() {
5258
// Set up the desired camera update.

lib/samples/map_controller_async.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class _MapControllerAsyncSampleState extends State<MapControllerAsyncSample> {
7676
// if the controller value is already available.
7777
final controller = await _completer.future;
7878

79+
// Bail out if the widget is already disposed.
80+
if (!mounted) return;
81+
7982
// Use the controller.
8083
controller.animateCamera(CameraUpdate.zoomIn());
8184
}

0 commit comments

Comments
 (0)