Skip to content

Commit

Permalink
🐛 Drop initialize when the controller has been already initialized (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Jan 14, 2022
1 parent 4031a7a commit 00f428b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/src/widgets/camera_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,17 @@ class CameraPickerState extends State<CameraPicker>

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
final CameraController? c = _controller;
// App state changed before we got the chance to initialize.
if (_controller == null || !controller.value.isInitialized) {
if (c == null || !c.value.isInitialized) {
return;
}
if (state == AppLifecycleState.inactive) {
controller.dispose();
} else if (state == AppLifecycleState.resumed) {
c.dispose();
} else if (state == AppLifecycleState.resumed && !c.value.isInitialized) {
// Drop initialize when the controller has been already initialized.
// This will typically resolve the lifecycle issue on iOS when permissions
// are requested for the first time.
initCameras(currentCamera);
}
}
Expand Down

0 comments on commit 00f428b

Please sign in to comment.