Skip to content

Commit 00f428b

Browse files
authored
🐛 Drop initialize when the controller has been already initialized (#70)
1 parent 4031a7a commit 00f428b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/src/widgets/camera_picker.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,17 @@ class CameraPickerState extends State<CameraPicker>
460460

461461
@override
462462
void didChangeAppLifecycleState(AppLifecycleState state) {
463+
final CameraController? c = _controller;
463464
// App state changed before we got the chance to initialize.
464-
if (_controller == null || !controller.value.isInitialized) {
465+
if (c == null || !c.value.isInitialized) {
465466
return;
466467
}
467468
if (state == AppLifecycleState.inactive) {
468-
controller.dispose();
469-
} else if (state == AppLifecycleState.resumed) {
469+
c.dispose();
470+
} else if (state == AppLifecycleState.resumed && !c.value.isInitialized) {
471+
// Drop initialize when the controller has been already initialized.
472+
// This will typically resolve the lifecycle issue on iOS when permissions
473+
// are requested for the first time.
470474
initCameras(currentCamera);
471475
}
472476
}

0 commit comments

Comments
 (0)