File tree Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 1+ ## 0.9.2+1
2+
3+ * Fixed camera controller throwing an exception when being replaced in the preview widget.
4+
15## 0.9.2
26
37* Added functions to pause and resume the camera preview.
Original file line number Diff line number Diff line change @@ -603,7 +603,9 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
603603 }
604604
605605 void onNewCameraSelected (CameraDescription cameraDescription) async {
606- final previousCameraController = controller;
606+ if (controller != null ) {
607+ await controller! .dispose ();
608+ }
607609
608610 final CameraController cameraController = CameraController (
609611 cameraDescription,
@@ -614,10 +616,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
614616
615617 controller = cameraController;
616618
617- if (mounted) {
618- setState (() {});
619- }
620-
621619 // If the controller is updated then update the UI.
622620 cameraController.addListener (() {
623621 if (mounted) setState (() {});
@@ -650,8 +648,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
650648 if (mounted) {
651649 setState (() {});
652650 }
653-
654- await previousCameraController? .dispose ();
655651 }
656652
657653 void onTakePictureButtonPressed () {
Original file line number Diff line number Diff line change @@ -824,4 +824,14 @@ class CameraController extends ValueNotifier<CameraValue> {
824824 );
825825 }
826826 }
827+
828+ @override
829+ void removeListener (VoidCallback listener) {
830+ // Prevent ValueListenableBuilder in CameraPreview widget from causing an
831+ // exception to be thrown by attempting to remove its own listener after
832+ // the controller has already been disposed.
833+ if (! _isDisposed) {
834+ super .removeListener (listener);
835+ }
836+ }
827837}
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ description: A Flutter plugin for getting information about and controlling the
44 and streaming image buffers to dart.
55repository : https://github.com/flutter/plugins/tree/master/packages/camera/camera
66issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
7- version : 0.9.2
7+ version : 0.9.2+1
88
99environment :
1010 sdk : " >=2.12.0 <3.0.0"
You can’t perform that action at this time.
0 commit comments