Skip to content

Commit 6a84532

Browse files
authored
CameraPickerConfig.enableScaledPreview (#108)
1 parent 457c6b4 commit 6a84532

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ that can be found in the LICENSE file. -->
66

77
## 3.3.1
88

9+
### New features
10+
11+
- Add `enableScaledPreview`. (#108)
12+
913
### Improvements
1014

1115
- Prevent unnecessary zoom updates. (#107)
@@ -32,7 +36,7 @@ that can be found in the LICENSE file. -->
3236

3337
### New features
3438

35-
- Introduce `onXFileCaptured`. (#87)
39+
- Add `onXFileCaptured`. (#87)
3640

3741
## 3.0.4
3842

example/lib/models/picker_method.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ List<PickMethod> get pickMethods {
116116
),
117117
),
118118
PickMethod(
119-
icon: '🔎',
119+
icon: '🔍',
120+
name: 'Prevent scaling for camera preview',
121+
description: 'Camera preview will not be scaled to cover '
122+
'the whole screen of the device, only fit with the raw size.',
123+
method: (BuildContext context) => CameraPicker.pickFromCamera(
124+
context,
125+
pickerConfig: const CameraPickerConfig(enableScaledPreview: false),
126+
),
127+
),
128+
PickMethod(
129+
icon: '🌀',
120130
name: 'Lower resolutions',
121131
description: 'Use a lower resolution preset might be helpful '
122132
'in some specific scenarios.',

lib/src/constants/config.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class CameraPickerConfig {
2323
this.enableExposureControlOnPoint = true,
2424
this.enablePinchToZoom = true,
2525
this.enablePullToZoomInRecord = true,
26+
this.enableScaledPreview = true,
2627
this.shouldDeletePreviewFile = false,
2728
this.shouldAutoPreviewVideo = false,
2829
this.maximumRecordingDuration = const Duration(seconds: 15),
@@ -78,6 +79,10 @@ class CameraPickerConfig {
7879
/// 用户是否可以在录制视频时上拉缩放
7980
final bool enablePullToZoomInRecord;
8081

82+
/// Whether the camera preview should be scaled during captures.
83+
/// 拍摄过程中相机预览是否需要缩放
84+
final bool enableScaledPreview;
85+
8186
/// {@template wechat_camera_picker.shouldDeletePreviewFile}
8287
/// Whether the preview file will be delete when pop.
8388
/// 返回页面时是否删除预览文件

lib/src/widgets/camera_picker.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,21 @@ class CameraPickerState extends State<CameraPicker>
13271327
controller,
13281328
preview,
13291329
);
1330-
preview = transformedWidget ?? preview;
1331-
1332-
preview = RotatedBox(
1333-
quarterTurns: -config.cameraQuarterTurns,
1334-
child: Transform.scale(
1330+
preview = Center(child: transformedWidget ?? preview);
1331+
// Scale the preview if the config is enabled.
1332+
if (config.enableScaledPreview) {
1333+
preview = Transform.scale(
13351334
scale: _effectiveCameraScale(constraints, controller),
1336-
child: Center(child: preview),
1337-
),
1338-
);
1335+
child: preview,
1336+
);
1337+
}
1338+
// Rotated the preview if the turns is valid.
1339+
if (config.cameraQuarterTurns % 4 != 0) {
1340+
preview = RotatedBox(
1341+
quarterTurns: -config.cameraQuarterTurns,
1342+
child: preview,
1343+
);
1344+
}
13391345
return preview;
13401346
}
13411347

0 commit comments

Comments
 (0)