Skip to content

Commit af2ddc5

Browse files
committed
⚡ Take good care of the app lifecycle.
1 parent e712491 commit af2ddc5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,17 @@ class CameraPickerState extends State<CameraPicker>
337337
if (controller == null || !controller.value.isInitialized) {
338338
return;
339339
}
340-
if (state == AppLifecycleState.inactive) {
341-
controller?.dispose();
342-
} else if (state == AppLifecycleState.resumed) {
343-
if (controller != null) {
344-
initCameras(currentCamera);
345-
}
340+
switch (state) {
341+
case AppLifecycleState.resumed:
342+
if (controller != null) {
343+
initCameras(currentCamera);
344+
}
345+
break;
346+
case AppLifecycleState.inactive:
347+
case AppLifecycleState.paused:
348+
case AppLifecycleState.detached:
349+
controller?.dispose();
350+
break;
346351
}
347352
}
348353

0 commit comments

Comments
 (0)