Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit b8786d3

Browse files
authored
Rebuild camera preview when camera value changes (#4197)
1 parent 08c9b40 commit b8786d3

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

packages/camera/camera/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.1+7
2+
3+
* Fix device orientation sometimes not affecting the camera preview orientation.
4+
15
## 0.8.1+6
26

37
* Remove references to the Android V1 embedding.

packages/camera/camera/lib/src/camera_preview.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@ class CameraPreview extends StatelessWidget {
2121
@override
2222
Widget build(BuildContext context) {
2323
return controller.value.isInitialized
24-
? AspectRatio(
25-
aspectRatio: _isLandscape()
26-
? controller.value.aspectRatio
27-
: (1 / controller.value.aspectRatio),
28-
child: Stack(
29-
fit: StackFit.expand,
30-
children: [
31-
_wrapInRotatedBox(child: controller.buildPreview()),
32-
child ?? Container(),
33-
],
34-
),
24+
? ValueListenableBuilder(
25+
valueListenable: controller,
26+
builder: (context, value, child) {
27+
return AspectRatio(
28+
aspectRatio: _isLandscape()
29+
? controller.value.aspectRatio
30+
: (1 / controller.value.aspectRatio),
31+
child: Stack(
32+
fit: StackFit.expand,
33+
children: [
34+
_wrapInRotatedBox(child: controller.buildPreview()),
35+
child ?? Container(),
36+
],
37+
),
38+
);
39+
},
40+
child: child,
3541
)
3642
: Container();
3743
}

packages/camera/camera/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: A Flutter plugin for getting information about and controlling the
44
and streaming image buffers to dart.
55
repository: https://github.com/flutter/plugins/tree/master/packages/camera/camera
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
7-
version: 0.8.1+6
7+
version: 0.8.1+7
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)