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 3 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.1+1

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

## 0.9.1

* Added `lensAperture`, `sensorExposureTime` and `sensorSensitivity` properties to the `CameraImage` dto.
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 @@ -594,7 +594,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 @@ -605,10 +607,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 @@ -641,8 +639,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 @@ -778,4 +778,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.1
version: 0.9.1+1

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