File tree 1 file changed +9
-3
lines changed
packages/camera/camera/example/lib 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -594,17 +594,21 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
594
594
}
595
595
596
596
void onNewCameraSelected (CameraDescription cameraDescription) async {
597
- if (controller != null ) {
598
- await controller! .dispose ();
599
- }
597
+ final previousCameraController = controller;
598
+
600
599
final CameraController cameraController = CameraController (
601
600
cameraDescription,
602
601
ResolutionPreset .medium,
603
602
enableAudio: enableAudio,
604
603
imageFormatGroup: ImageFormatGroup .jpeg,
605
604
);
605
+
606
606
controller = cameraController;
607
607
608
+ if (mounted) {
609
+ setState (() {});
610
+ }
611
+
608
612
// If the controller is updated then update the UI.
609
613
cameraController.addListener (() {
610
614
if (mounted) setState (() {});
@@ -637,6 +641,8 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
637
641
if (mounted) {
638
642
setState (() {});
639
643
}
644
+
645
+ await previousCameraController? .dispose ();
640
646
}
641
647
642
648
void onTakePictureButtonPressed () {
You can’t perform that action at this time.
0 commit comments