Skip to content

Commit 61ae8ea

Browse files
committed
♻️ Remove is from options.
1 parent 017f15e commit 61ae8ea

File tree

4 files changed

+36
-47
lines changed

4 files changed

+36
-47
lines changed

README-ZH.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ Flutter SDK:`>=1.20.0` 。
4747

4848
| 参数名 | 类型 | 描述 | 默认值 |
4949
| ------------------------ | ------------------------------ | ----------------------------------------------------------------- | -------------------------------------- |
50-
| isAllowPinchToZoom | `bool` | 用户是否可以在界面上双指缩放相机对焦 | `true` |
51-
| isAllowRecording | `bool` | 选择器是否可以录像 | `false` |
52-
| isOnlyAllowRecording | `bool` | 选择器是否仅可以录像。只在 `isAllowRecording``true` 时有效。 | `false` |
50+
| allowPinchToZoom | `bool` | 用户是否可以在界面上双指缩放相机对焦 | `true` |
51+
| allowRecording | `bool` | 选择器是否可以录像 | `false` |
52+
| onlyAllowRecording | `bool` | 选择器是否仅可以录像。只在 `isAllowRecording``true` 时有效。 | `false` |
5353
| enabledAudio | `bool` | 选择器是否需要录制音频。只于录像配合有效。 | `true` |
5454
| maximumRecordingDuration | `Duration` | 录制视频最长时长 | `const Duration(seconds: 15)` |
5555
| theme | `ThemeData` | 选择器的主题 | `CameraPicker.themeData(C.themeColor)` |
@@ -63,9 +63,3 @@ Flutter SDK:`>=1.20.0` 。
6363
```dart
6464
final AssetEntity entity = await CameraPicker.pickFromCamera(context);
6565
```
66-
67-
在选择器唤起后,点击拍摄按钮以拍照。
68-
69-
如果 `isAllowPinchToZoom``true`,双指捏合界面可以缩放。
70-
71-
如果 `isAllowRecording``true`,长按拍摄按钮可以录像。

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ Reference:
7373

7474
| Name | Type | Description | Default Value |
7575
| ------------------------ | ------------------------------ | -------------------------------------------------------------------------------------------- | -------------------------------------- |
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` |
76+
| allowPinchToZoom | `bool` | Whether users can zoom the camera by pinch. | `true` |
77+
| allowRecording | `bool` | Whether the picker can record video. | `false` |
78+
| onlyAllowRecording | `bool` | Whether the picker can only record video. Only available when `isAllowRecording` is `true `. | `false` |
7979
| enableAudio | `bool` | Whether Whether the picker should record audio. Only available with recording. | `true` |
8080
| maximumRecordingDuration | `Duration` | The maximum duration of the video recording process. | `const Duration(seconds: 15)` |
8181
| theme | `ThemeData` | Theme data for the picker. | `CameraPicker.themeData(C.themeColor)` |
@@ -89,9 +89,3 @@ Reference:
8989
```dart
9090
final AssetEntity entity = await CameraPicker.pickFromCamera(context);
9191
```
92-
93-
After called and the picker displayed,tap the shooting button to take a picture.
94-
95-
If `isAllowPinchToZoom` is `true`, pinch on the screen can zoom the camera.
96-
97-
If `isAllowRecording` is `true`, long press the shooting button to record a video.

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class _MyHomePageState extends State<MyHomePage> {
4848
onPressed: () {
4949
CameraPicker.pickFromCamera(
5050
context,
51-
isAllowRecording: true,
51+
allowRecording: true,
5252
);
5353
},
5454
tooltip: 'Increment',

lib/src/widget/camera_picker.dart

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ const Duration _kRouteDuration = Duration(milliseconds: 300);
2828
class CameraPicker extends StatefulWidget {
2929
CameraPicker({
3030
Key key,
31-
this.isAllowPinchToZoom = true,
32-
this.isAllowRecording = false,
33-
this.isOnlyAllowRecording = false,
31+
this.allowRecording = false,
32+
this.onlyAllowRecording = false,
3433
this.enableAudio = true,
34+
this.enablePinchToZoom = true,
3535
this.maximumRecordingDuration = const Duration(seconds: 15),
3636
this.theme,
3737
this.resolutionPreset = ResolutionPreset.max,
3838
this.cameraQuarterTurns = 0,
3939
this.foregroundBuilder,
4040
CameraPickerTextDelegate textDelegate,
4141
}) : assert(
42-
isAllowRecording == true || isOnlyAllowRecording != true,
42+
allowRecording == true || onlyAllowRecording != true,
4343
'Recording mode error.',
4444
),
4545
assert(
@@ -48,7 +48,7 @@ class CameraPicker extends StatefulWidget {
4848
),
4949
super(key: key) {
5050
Constants.textDelegate = textDelegate ??
51-
(isAllowRecording
51+
(allowRecording
5252
? DefaultCameraPickerTextDelegateWithRecording()
5353
: DefaultCameraPickerTextDelegate());
5454
}
@@ -57,22 +57,22 @@ class CameraPicker extends StatefulWidget {
5757
/// 摄像机视图顺时针旋转次数,每次90度
5858
final int cameraQuarterTurns;
5959

60-
/// Whether users can zoom the camera by pinch.
61-
/// 用户是否可以在界面上双指缩放相机对焦
62-
final bool isAllowPinchToZoom;
63-
6460
/// Whether the picker can record video.
6561
/// 选择器是否可以录像
66-
final bool isAllowRecording;
62+
final bool allowRecording;
6763

6864
/// Whether the picker can record video.
6965
/// 选择器是否可以录像
70-
final bool isOnlyAllowRecording;
66+
final bool onlyAllowRecording;
7167

7268
/// Whether the picker should record audio.
7369
/// 选择器录像时是否需要录制声音
7470
final bool enableAudio;
7571

72+
/// Whether users can zoom the camera by pinch.
73+
/// 用户是否可以在界面上双指缩放相机对焦
74+
final bool enablePinchToZoom;
75+
7676
/// The maximum duration of the video recording process.
7777
/// 录制视频最长时长
7878
///
@@ -96,9 +96,9 @@ class CameraPicker extends StatefulWidget {
9696
/// 通过相机创建 [AssetEntity] 的静态方法
9797
static Future<AssetEntity> pickFromCamera(
9898
BuildContext context, {
99-
bool isAllowPinchToZoom = true,
100-
bool isAllowRecording = false,
101-
bool isOnlyAllowRecording = false,
99+
bool allowPinchToZoom = true,
100+
bool allowRecording = false,
101+
bool onlyAllowRecording = false,
102102
bool enableAudio = true,
103103
Duration maximumRecordingDuration = const Duration(seconds: 15),
104104
ThemeData theme,
@@ -107,7 +107,7 @@ class CameraPicker extends StatefulWidget {
107107
ResolutionPreset resolutionPreset = ResolutionPreset.max,
108108
Widget Function(CameraValue) foregroundBuilder,
109109
}) async {
110-
if (isAllowRecording != true && isOnlyAllowRecording == true) {
110+
if (allowRecording != true && onlyAllowRecording == true) {
111111
throw ArgumentError('Recording mode error.');
112112
}
113113
if (resolutionPreset == null) {
@@ -119,9 +119,9 @@ class CameraPicker extends StatefulWidget {
119119
).push<AssetEntity>(
120120
SlidePageTransitionBuilder<AssetEntity>(
121121
builder: CameraPicker(
122-
isAllowPinchToZoom: isAllowPinchToZoom,
123-
isAllowRecording: isAllowRecording,
124-
isOnlyAllowRecording: isOnlyAllowRecording,
122+
enablePinchToZoom: allowPinchToZoom,
123+
allowRecording: allowRecording,
124+
onlyAllowRecording: onlyAllowRecording,
125125
enableAudio: enableAudio,
126126
maximumRecordingDuration: maximumRecordingDuration,
127127
theme: theme,
@@ -273,22 +273,22 @@ class CameraPickerState extends State<CameraPicker>
273273
274274
/// Whether users can zoom the camera by pinch. (A non-null wrapper)
275275
/// 用户是否可以在界面上双指缩放相机对焦(非空包装)
276-
bool get isAllowPinchToZoom => widget.isAllowPinchToZoom ?? true;
276+
bool get allowPinchToZoom => widget.enablePinchToZoom ?? true;
277277

278278
/// Whether the picker can record video. (A non-null wrapper)
279279
/// 选择器是否可以录像(非空包装)
280-
bool get isAllowRecording => widget.isAllowRecording ?? false;
280+
bool get allowRecording => widget.allowRecording ?? false;
281281

282282
/// Whether the picker can only record video. (A non-null wrapper)
283283
/// 选择器是否仅可以录像(非空包装)
284-
bool get isOnlyAllowRecording => widget.isOnlyAllowRecording ?? false;
284+
bool get onlyAllowRecording => widget.onlyAllowRecording ?? false;
285285

286286
/// Whether the picker should record audio. (A non-null wrapper)
287287
/// 选择器录制视频时,是否需要录制音频(非空包装)
288288
///
289289
/// No audio integration required when it's only for camera.
290290
/// 在仅允许拍照时不需要启用音频
291-
bool get enableAudio => isAllowRecording && (widget.enableAudio ?? true);
291+
bool get enableAudio => allowRecording && (widget.enableAudio ?? true);
292292

293293
/// Getter for `widget.maximumRecordingDuration` .
294294
Duration get maximumRecordingDuration => widget.maximumRecordingDuration;
@@ -742,11 +742,11 @@ class CameraPickerState extends State<CameraPicker>
742742
final Size outerSize = Size.square(Screens.width / 3.5);
743743
return Listener(
744744
behavior: HitTestBehavior.opaque,
745-
onPointerUp: isAllowRecording ? recordDetectionCancel : null,
745+
onPointerUp: allowRecording ? recordDetectionCancel : null,
746746
child: InkWell(
747747
borderRadius: maxBorderRadius,
748-
onTap: !isOnlyAllowRecording ? takePicture : null,
749-
onLongPress: isAllowRecording ? recordDetection : null,
748+
onTap: !onlyAllowRecording ? takePicture : null,
749+
onLongPress: allowRecording ? recordDetection : null,
750750
child: SizedBox.fromSize(
751751
size: outerSize,
752752
child: Stack(
@@ -866,9 +866,10 @@ class CameraPickerState extends State<CameraPicker>
866866
onPointerDown: (_) => _pointers++,
867867
onPointerUp: (_) => _pointers--,
868868
child: GestureDetector(
869-
onScaleStart: isAllowPinchToZoom ? _handleScaleStart : null,
870-
onScaleUpdate: isAllowPinchToZoom ? _handleScaleUpdate : null,
871-
onDoubleTap: switchCameras,
869+
onScaleStart: allowPinchToZoom ? _handleScaleStart : null,
870+
onScaleUpdate: allowPinchToZoom ? _handleScaleUpdate : null,
871+
// Enabled cameras switching by default if we have multiple cameras.
872+
onDoubleTap: cameras.length > 1 ? switchCameras : null,
872873
child: CameraPreview(controller),
873874
),
874875
);

0 commit comments

Comments
 (0)