Skip to content

Commit 74e73cb

Browse files
lockCaptureOrientation (#68)
Co-authored-by: Alex Li <[email protected]>
1 parent cae6bdc commit 74e73cb

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

README-ZH.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Flutter SDK:`>=2.0.0` 。
7777
| cameraQuarterTurns | `int` | 摄像机视图顺时针旋转次数,每次 90 度 | `0` |
7878
| imageFormatGroup | `ImageFormatGroup` | 输出图像的格式描述 | `ImageFormatGroup.unknown` |
7979
| preferredLensDirection | `CameraLensDirection` | 首次使用相机时首选的镜头方向 | `CameraLensDirection.back` |
80+
| lockCaptureOrientation | `DeviceOrientation?` | 摄像机在拍摄时锁定的旋转角度 | null |
8081
| foregroundBuilder | `Widget Function(CameraValue)?` | 覆盖在相机预览上方的前景构建 | null |
8182
| onEntitySaving | `EntitySaveCallback?` | 在查看器中保存图片时的回调 | null |
8283
| onError | `CameraErrorHandler?` | 拍摄照片过程中的自定义错误处理 | null |

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Flutter SDK: `>=2.0.0` .
7878
| cameraQuarterTurns | `int` | The number of clockwise quarter turns the camera view should be rotated. | `0` |
7979
| imageFormatGroup | `ImageFormatGroup` | Describes the output of the raw image format. | `ImageFormatGroup.unknown` |
8080
| preferredLensDirection | `CameraLensDirection` | Which lens direction is preferred when first using the camera. | `CameraLensDirection.back` |
81+
| lockCaptureOrientation | `DeviceOrientation?` | Whether the camera should be locked to the specific orientation during captures. | null |
8182
| foregroundBuilder | `Widget Function(CameraValue)?` | The foreground widget builder which will cover the whole camera preview. | null |
8283
| onEntitySaving | `EntitySaveCallback?` | The callback type define for saving entity in the viewer. | null |
8384
| onError | `CameraErrorHandler?` | The error handler when any error occurred during the picking process. | null |

lib/src/widgets/camera_picker.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class CameraPicker extends StatefulWidget {
4949
this.resolutionPreset = ResolutionPreset.max,
5050
this.imageFormatGroup = ImageFormatGroup.unknown,
5151
this.preferredLensDirection = CameraLensDirection.back,
52+
this.lockCaptureOrientation,
5253
this.cameraQuarterTurns = 0,
5354
this.foregroundBuilder,
5455
this.onEntitySaving,
@@ -75,6 +76,11 @@ class CameraPicker extends StatefulWidget {
7576
}
7677
}
7778

79+
/// Whether the camera should be locked to the specific orientation
80+
/// during captures.
81+
/// 摄像机在拍摄时锁定的旋转角度
82+
final DeviceOrientation? lockCaptureOrientation;
83+
7884
/// The number of clockwise quarter turns the camera view should be rotated.
7985
/// 摄像机视图顺时针旋转次数,每次90度
8086
final int cameraQuarterTurns;
@@ -181,6 +187,7 @@ class CameraPicker extends StatefulWidget {
181187
ResolutionPreset resolutionPreset = ResolutionPreset.max,
182188
ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown,
183189
CameraLensDirection preferredLensDirection = CameraLensDirection.back,
190+
DeviceOrientation? lockCaptureOrientation,
184191
Widget Function(CameraValue)? foregroundBuilder,
185192
EntitySaveCallback? onEntitySaving,
186193
CameraErrorHandler? onError,
@@ -212,6 +219,7 @@ class CameraPicker extends StatefulWidget {
212219
resolutionPreset: resolutionPreset,
213220
imageFormatGroup: imageFormatGroup,
214221
preferredLensDirection: preferredLensDirection,
222+
lockCaptureOrientation: lockCaptureOrientation,
215223
foregroundBuilder: foregroundBuilder,
216224
onEntitySaving: onEntitySaving,
217225
onError: onError,
@@ -571,10 +579,13 @@ class CameraPickerState extends State<CameraPicker>
571579

572580
try {
573581
await controller.initialize();
582+
// Call recording preparation first.
574583
if (shouldPrepareForVideoRecording) {
575584
await controller.prepareForVideoRecording();
576585
}
586+
// Then call other asynchronous methods.
577587
Future.wait(<Future<void>>[
588+
controller.lockCaptureOrientation(widget.lockCaptureOrientation),
578589
(() async => _maxAvailableExposureOffset =
579590
await controller.getMaxExposureOffset())(),
580591
(() async => _minAvailableExposureOffset =

0 commit comments

Comments
 (0)