Skip to content

Commit

Permalink
🐛 Nullable camera description
Browse files Browse the repository at this point in the history
Fixes #261
  • Loading branch information
AlexV525 committed Aug 21, 2024
1 parent 61ae1f7 commit 2a5a64c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CameraPickerState extends State<CameraPicker>

/// Available cameras.
/// 可用的相机实例
late List<CameraDescription> cameras;
List<CameraDescription> cameras = [];

/// Whether the controller is handling method calls.
/// 相机控制器是否在处理方法调用
Expand Down Expand Up @@ -270,7 +270,9 @@ class CameraPickerState extends State<CameraPicker>
void didChangeAppLifecycleState(AppLifecycleState state) {
final CameraController? c = innerController;
if (state == AppLifecycleState.resumed && !accessDenied) {
initCameras(cameraDescription: currentCamera);
initCameras(
cameraDescription: cameras.elementAtOrNull(currentCameraIndex),
);
} else if (c == null || !c.value.isInitialized) {
// App state changed before we got the chance to initialize.
return;
Expand Down

0 comments on commit 2a5a64c

Please sign in to comment.