Skip to content

Commit 762ddd4

Browse files
committed
Fix: dispose existing camera controller before initializing a new one
1 parent cbd4363 commit 762ddd4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

modules/camera/lib/camera.dart

+6
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ class CameraState extends EWidgetState<Camera> with WidgetsBindingObserver {
351351
}
352352

353353
Future<void> setCamera({CameraDescription? cameraDescription}) async {
354+
// If a camera controller has already been initialized, dispose it.
355+
if (widget._controller.cameraController != null) {
356+
await widget._controller.cameraController!.dispose();
357+
widget._controller.cameraController = null;
358+
}
359+
354360
CameraDescription targetCamera = cameraDescription ?? cameras[0];
355361

356362
widget._controller.cameraController = CameraController(

0 commit comments

Comments
 (0)