Skip to content

Commit eb688b9

Browse files
committed
✨ Add shouldDeletePreviewFile.
Remove `DeviceUtils`. ref: #23 (comment) .
1 parent 56acfad commit eb688b9

File tree

6 files changed

+30
-42
lines changed

6 files changed

+30
-42
lines changed

README-ZH.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Flutter SDK:`>=1.20.0` 。
5353
| enableSetExposure | `bool` | 用户是否可以在界面上通过点击设定曝光点 | `true` |
5454
| enableExposureControlOnPoint | `bool` | 用户是否可以根据已经设置的曝光点调节曝光度 | `true` |
5555
| enablePinchToZoom | `bool` | 用户是否可以在界面上双指缩放相机对焦 | `true` |
56+
| shouldDeletePreviewFile | `bool` | 返回页面时是否删除预览文件 | `false` |
5657
| maximumRecordingDuration | `Duration` | 录制视频最长时长 | `const Duration(seconds: 15)` |
5758
| theme | `ThemeData` | 选择器的主题 | `CameraPicker.themeData(C.themeColor)` |
5859
| textDelegate | `CameraPickerTextDelegate` | 控制部件中的文字实现 | `DefaultCameraPickerTextDelegate` |

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Reference:
7979
| enableSetExposure | `bool` | Whether users can set the exposure point by tapping. | `true` |
8080
| enableExposureControlOnPoint | `bool` | Whether users can adjust exposure according to the set point. | `true` |
8181
| enablePinchToZoom | `bool` | Whether users can zoom the camera by pinch. | `true` |
82+
| shouldDeletePreviewFile | `bool` | Whether the preview file will be delete when pop. | `false` |
8283
| maximumRecordingDuration | `Duration` | The maximum duration of the video recording process. | `const Duration(seconds: 15)` |
8384
| theme | `ThemeData` | Theme data for the picker. | `CameraPicker.themeData(C.themeColor)` |
8485
| textDelegate | `CameraPickerTextDelegate` | Text delegate that controls text in widgets. | `DefaultCameraPickerTextDelegate` |

lib/src/constants/constants.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:wechat_camera_picker/wechat_camera_picker.dart';
1212
export 'package:photo_manager/photo_manager.dart';
1313

1414
export '../delegates/camera_picker_text_delegate.dart';
15-
export '../utils/device_utils.dart';
1615
export 'colors.dart';
1716
export 'screens.dart';
1817

lib/src/utils/device_utils.dart

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/src/widget/camera_picker.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class CameraPicker extends StatefulWidget {
3535
this.enableSetExposure = true,
3636
this.enableExposureControlOnPoint = true,
3737
this.enablePinchToZoom = true,
38+
this.shouldDeletePreviewFile = false,
3839
this.maximumRecordingDuration = const Duration(seconds: 15),
3940
this.theme,
4041
this.resolutionPreset = ResolutionPreset.max,
@@ -48,6 +49,7 @@ class CameraPicker extends StatefulWidget {
4849
assert(enablePinchToZoom != null),
4950
assert(enableSetExposure != null),
5051
assert(enableExposureControlOnPoint != null),
52+
assert(shouldDeletePreviewFile != null),
5153
assert(maximumRecordingDuration != null),
5254
assert(resolutionPreset != null),
5355
assert(cameraQuarterTurns != null),
@@ -94,6 +96,10 @@ class CameraPicker extends StatefulWidget {
9496
/// 用户是否可以在界面上双指缩放相机对焦
9597
final bool enablePinchToZoom;
9698

99+
/// Whether the preview file will be delete when pop.
100+
/// 返回页面时是否删除预览文件
101+
final bool shouldDeletePreviewFile;
102+
97103
/// The maximum duration of the video recording process.
98104
/// 录制视频最长时长
99105
///
@@ -130,6 +136,7 @@ class CameraPicker extends StatefulWidget {
130136
bool enableSetExposure = true,
131137
bool enableExposureControlOnPoint = true,
132138
bool enablePinchToZoom = true,
139+
bool shouldDeletePreviewFile = false,
133140
Duration maximumRecordingDuration = const Duration(seconds: 15),
134141
ThemeData theme,
135142
int cameraQuarterTurns = 0,
@@ -156,6 +163,7 @@ class CameraPicker extends StatefulWidget {
156163
enableSetExposure: enableSetExposure,
157164
enableExposureControlOnPoint: enableExposureControlOnPoint,
158165
enablePinchToZoom: enablePinchToZoom,
166+
shouldDeletePreviewFile: shouldDeletePreviewFile,
159167
maximumRecordingDuration: maximumRecordingDuration,
160168
theme: theme,
161169
cameraQuarterTurns: cameraQuarterTurns,
@@ -329,6 +337,8 @@ class CameraPickerState extends State<CameraPicker>
329337

330338
bool get enablePinchToZoom => widget.enablePinchToZoom;
331339

340+
bool get shouldDeletePreviewFile => widget.shouldDeletePreviewFile;
341+
332342
/// Getter for `widget.maximumRecordingDuration` .
333343
Duration get maximumRecordingDuration => widget.maximumRecordingDuration;
334344

@@ -642,6 +652,7 @@ class CameraPickerState extends State<CameraPicker>
642652
pickerType: CameraPickerViewType.image,
643653
previewXFile: await controller.takePicture(),
644654
theme: theme,
655+
shouldDeletePreviewFile: shouldDeletePreviewFile,
645656
);
646657
if (entity != null) {
647658
Navigator.of(context).pop(entity);
@@ -721,6 +732,7 @@ class CameraPickerState extends State<CameraPicker>
721732
pickerType: CameraPickerViewType.video,
722733
previewXFile: file,
723734
theme: theme,
735+
shouldDeletePreviewFile: shouldDeletePreviewFile,
724736
);
725737
if (entity != null) {
726738
Navigator.of(context).pop(entity);

lib/src/widget/camera_picker_viewer.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ class CameraPickerViewer extends StatefulWidget {
2424
@required this.pickerType,
2525
@required this.previewXFile,
2626
@required this.theme,
27-
}) : assert(
28-
theme != null && previewXFile != null && pickerState != null,
29-
),
27+
this.shouldDeletePreviewFile = false,
28+
}) : assert(pickerState != null),
29+
assert(pickerType != null),
30+
assert(previewXFile != null),
31+
assert(theme != null),
32+
assert(shouldDeletePreviewFile != null),
3033
super(key: key);
3134

3235
/// State of the picker.
@@ -45,6 +48,10 @@ class CameraPickerViewer extends StatefulWidget {
4548
/// 选择器使用的主题
4649
final ThemeData theme;
4750

51+
/// Whether the preview file will be delete when pop.
52+
/// 返回页面时是否删除预览文件
53+
final bool shouldDeletePreviewFile;
54+
4855
/// Static method to push with the navigator.
4956
/// 跳转至选择预览的静态方法
5057
static Future<AssetEntity> pushToViewer(
@@ -53,13 +60,15 @@ class CameraPickerViewer extends StatefulWidget {
5360
@required CameraPickerViewType pickerType,
5461
@required XFile previewXFile,
5562
@required ThemeData theme,
63+
bool shouldDeletePreviewFile = false,
5664
}) async {
5765
try {
5866
final Widget viewer = CameraPickerViewer(
5967
pickerState: pickerState,
6068
pickerType: pickerType,
6169
previewXFile: previewXFile,
6270
theme: theme,
71+
shouldDeletePreviewFile: shouldDeletePreviewFile,
6372
);
6473
final PageRouteBuilder<AssetEntity> pageRoute =
6574
PageRouteBuilder<AssetEntity>(
@@ -106,6 +115,8 @@ class _CameraPickerViewerState extends State<CameraPickerViewer> {
106115

107116
ThemeData get theme => widget.theme;
108117

118+
bool get shouldDeletePreviewFile => widget.shouldDeletePreviewFile;
119+
109120
/* End of widget getter */
110121

111122
/// Controller for the video player.
@@ -216,14 +227,8 @@ class _CameraPickerViewerState extends State<CameraPickerViewer> {
216227
}
217228

218229
saveFuture.then((AssetEntity entity) {
219-
if (Platform.isAndroid) {
220-
if (!DeviceUtils.isLowerThanAndroidQ && previewFile.existsSync()) {
221-
previewFile.delete();
222-
}
223-
} else {
224-
if (previewFile.existsSync()) {
225-
previewFile.delete();
226-
}
230+
if (shouldDeletePreviewFile && previewFile.existsSync()) {
231+
previewFile.delete();
227232
}
228233
Navigator.of(context).pop(entity);
229234
});

0 commit comments

Comments
 (0)