Skip to content

Commit 3a12f7c

Browse files
committed
✨ Add isAllowPinchToZoom .
1 parent a2245c0 commit 3a12f7c

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

README-ZH.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,26 @@ Flutter SDK:`>=1.20.0` 。
4545

4646
## 使用方法 📖
4747

48-
| 参数名 | 类型 | 描述 | 默认值 |
49-
| ------------------------ | -------------------------- | ----------------------------------------------------------------- | -------------------------------------- |
50-
| isAllowRecording | `bool` | 选择器是否可以录像 | `false` |
51-
| isOnlyAllowRecording | `bool` | 选择器是否仅可以录像。只在 `isAllowRecording``true` 时有效。 | `false` |
52-
| enabledAudio | `bool` | 选择器是否需要录制音频。只于录像配合有效。 | `true` |
53-
| maximumRecordingDuration | `Duration` | 录制视频最长时长 | `const Duration(seconds: 15)` |
54-
| theme | `ThemeData` | 选择器的主题 | `CameraPicker.themeData(C.themeColor)` |
55-
| textDelegate | `CameraPickerTextDelegate` | 控制部件中的文字实现 | `DefaultCameraPickerTextDelegate` |
56-
| resolutionPreset | `ResolutionPreset` | 相机的分辨率预设 | `ResolutionPreset.max` |
57-
| cameraQuarterTurns | `int` | 摄像机视图顺时针旋转次数,每次90度 | `0` |
48+
| 参数名 | 类型 | 描述 | 默认值 |
49+
| ------------------------ | ------------------------------ | ----------------------------------------------------------------- | -------------------------------------- |
50+
| isAllowPinchToZoom | `bool` | 用户是否可以在界面上双指缩放相机对焦 | `true` |
51+
| isAllowRecording | `bool` | 选择器是否可以录像 | `false` |
52+
| isOnlyAllowRecording | `bool` | 选择器是否仅可以录像。只在 `isAllowRecording``true` 时有效。 | `false` |
53+
| enabledAudio | `bool` | 选择器是否需要录制音频。只于录像配合有效。 | `true` |
54+
| maximumRecordingDuration | `Duration` | 录制视频最长时长 | `const Duration(seconds: 15)` |
55+
| theme | `ThemeData` | 选择器的主题 | `CameraPicker.themeData(C.themeColor)` |
56+
| textDelegate | `CameraPickerTextDelegate` | 控制部件中的文字实现 | `DefaultCameraPickerTextDelegate` |
57+
| resolutionPreset | `ResolutionPreset` | 相机的分辨率预设 | `ResolutionPreset.max` |
58+
| cameraQuarterTurns | `int` | 摄像机视图顺时针旋转次数,每次90度 | `0` |
59+
5860
### 简单的使用方法
5961

6062
```dart
6163
final AssetEntity entity = await CameraPicker.pickFromCamera(context);
6264
```
6365

64-
在选择器唤起后,并且 `isAllowRecording``true`,点击拍摄按钮以拍照,长按拍摄按钮以录像。
66+
在选择器唤起后,点击拍摄按钮以拍照。
67+
68+
如果 `isAllowPinchToZoom``true`,双指捏合界面可以缩放。
69+
70+
如果 `isAllowRecording``true`,长按拍摄按钮可以录像。

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,26 @@ Reference:
7171

7272
## Usage 📖
7373

74-
| Name | Type | Description | Default Value |
75-
| ------------------------ | -------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------- |
76-
| isAllowRecording | `bool` | Whether the picker can record video. | `false` |
77-
| isOnlyAllowRecording | `bool` | Whether the picker can only record video. Only available when `isAllowRecording` is `true `. | `false` |
78-
| enableAudio | `bool` | Whether Whether the picker should record audio. Only available with recording. | `true` |
79-
| maximumRecordingDuration | `Duration` | The maximum duration of the video recording process. | `const Duration(seconds: 15)` |
80-
| theme | `ThemeData` | Theme data for the picker. | `CameraPicker.themeData(C.themeColor)` |
81-
| textDelegate | `CameraPickerTextDelegate` | Text delegate that controls text in widgets. | `DefaultCameraPickerTextDelegate` |
82-
| resolutionPreset | `ResolutionPreset` | Present resolution for the camera. | `ResolutionPreset.max` |
83-
| cameraQuarterTurns | `int` | The number of clockwise quarter turns the camera view should be rotated. | `0` |
74+
| Name | Type | Description | Default Value |
75+
| ------------------------ | ------------------------------ | -------------------------------------------------------------------------------------------- | -------------------------------------- |
76+
| isAllowPinchToZoom | `bool` | Whether users can zoom the camera by pinch. | `true` |
77+
| isAllowRecording | `bool` | Whether the picker can record video. | `false` |
78+
| isOnlyAllowRecording | `bool` | Whether the picker can only record video. Only available when `isAllowRecording` is `true `. | `false` |
79+
| enableAudio | `bool` | Whether Whether the picker should record audio. Only available with recording. | `true` |
80+
| maximumRecordingDuration | `Duration` | The maximum duration of the video recording process. | `const Duration(seconds: 15)` |
81+
| theme | `ThemeData` | Theme data for the picker. | `CameraPicker.themeData(C.themeColor)` |
82+
| textDelegate | `CameraPickerTextDelegate` | Text delegate that controls text in widgets. | `DefaultCameraPickerTextDelegate` |
83+
| resolutionPreset | `ResolutionPreset` | Present resolution for the camera. | `ResolutionPreset.max` |
84+
| cameraQuarterTurns | `int` | The number of clockwise quarter turns the camera view should be rotated. | `0` |
8485

8586
### Simple usage
8687

8788
```dart
8889
final AssetEntity entity = await CameraPicker.pickFromCamera(context);
8990
```
9091

91-
After called and the picker displayed, plus `isAllowRecording` is `true`, tap the shooting button to take a picture, long press the shooting button to record a video.
92+
After called and the picker displayed,tap the shooting button to take a picture.
93+
94+
If `isAllowPinchToZoom` is `true`, pinch on the screen can zoom the camera.
95+
96+
If `isAllowRecording` is `true`, long press the shooting button to record a video.

lib/src/widget/camera_picker.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const Duration _kRouteDuration = Duration(milliseconds: 300);
2828
class CameraPicker extends StatefulWidget {
2929
CameraPicker({
3030
Key key,
31+
this.isAllowPinchToZoom = true,
3132
this.isAllowRecording = false,
3233
this.isOnlyAllowRecording = false,
3334
this.enableAudio = true,
@@ -55,6 +56,10 @@ class CameraPicker extends StatefulWidget {
5556
/// 摄像机视图顺时针旋转次数,每次90度
5657
final int cameraQuarterTurns;
5758

59+
/// Whether users can zoom the camera by pinch.
60+
/// 用户是否可以在界面上双指缩放相机对焦
61+
final bool isAllowPinchToZoom;
62+
5863
/// Whether the picker can record video.
5964
/// 选择器是否可以录像
6065
final bool isAllowRecording;
@@ -86,6 +91,7 @@ class CameraPicker extends StatefulWidget {
8691
/// 通过相机创建 [AssetEntity] 的静态方法
8792
static Future<AssetEntity> pickFromCamera(
8893
BuildContext context, {
94+
bool isAllowPinchToZoom = true,
8995
bool isAllowRecording = false,
9096
bool isOnlyAllowRecording = false,
9197
bool enableAudio = true,
@@ -107,6 +113,7 @@ class CameraPicker extends StatefulWidget {
107113
).push<AssetEntity>(
108114
SlidePageTransitionBuilder<AssetEntity>(
109115
builder: CameraPicker(
116+
isAllowPinchToZoom: isAllowPinchToZoom,
110117
isAllowRecording: isAllowRecording,
111118
isOnlyAllowRecording: isOnlyAllowRecording,
112119
enableAudio: enableAudio,
@@ -257,6 +264,10 @@ class CameraPickerState extends State<CameraPicker>
257264
////////////////////////////// Global Getters //////////////////////////////
258265
////////////////////////////////////////////////////////////////////////////
259266
267+
/// Whether users can zoom the camera by pinch. (A non-null wrapper)
268+
/// 用户是否可以在界面上双指缩放相机对焦(非空包装)
269+
bool get isAllowPinchToZoom => widget.isAllowPinchToZoom ?? true;
270+
260271
/// Whether the picker can record video. (A non-null wrapper)
261272
/// 选择器是否可以录像(非空包装)
262273
bool get isAllowRecording => widget.isAllowRecording ?? false;
@@ -848,8 +859,8 @@ class CameraPickerState extends State<CameraPicker>
848859
onPointerDown: (_) => _pointers++,
849860
onPointerUp: (_) => _pointers--,
850861
child: GestureDetector(
851-
onScaleStart: _handleScaleStart,
852-
onScaleUpdate: _handleScaleUpdate,
862+
onScaleStart: isAllowPinchToZoom ? _handleScaleStart : null,
863+
onScaleUpdate: isAllowPinchToZoom ? _handleScaleUpdate : null,
853864
onDoubleTap: switchCameras,
854865
child: CameraPreview(controller),
855866
),

0 commit comments

Comments
 (0)