Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.2+1

* Fixed camera controller throwing an exception when being replaced in the preview widget.

## 0.9.2

* Added functions to pause and resume the camera preview.
Expand Down
10 changes: 3 additions & 7 deletions packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,9 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
}

void onNewCameraSelected(CameraDescription cameraDescription) async {
final previousCameraController = controller;
if (controller != null) {
await controller!.dispose();
}

final CameraController cameraController = CameraController(
cameraDescription,
Expand All @@ -614,10 +616,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>

controller = cameraController;

if (mounted) {
setState(() {});
}

// If the controller is updated then update the UI.
cameraController.addListener(() {
if (mounted) setState(() {});
Expand Down Expand Up @@ -650,8 +648,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
if (mounted) {
setState(() {});
}

await previousCameraController?.dispose();
}

void onTakePictureButtonPressed() {
Expand Down
10 changes: 10 additions & 0 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,14 @@ class CameraController extends ValueNotifier<CameraValue> {
);
}
}

@override
void removeListener(VoidCallback listener) {
// Prevent ValueListenableBuilder in CameraPreview widget from causing an
// exception to be thrown by attempting to remove its own listener after
// the controller has already been disposed.
if (!_isDisposed) {
super.removeListener(listener);
}
}
}
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for getting information about and controlling the
and streaming image buffers to dart.
repository: https://github.com/flutter/plugins/tree/master/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.2
version: 0.9.2+1

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down