Skip to content

Commit 3effc8e

Browse files
authored
♻️ Make XFileCapturedCallback returns a boolean result (#89)
1 parent d792f4b commit 3effc8e

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lib/src/constants/type_defs.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ typedef PreviewTransformBuilder = Widget? Function(
6363
/// The callback type definition when the XFile is captured by the camera.
6464
/// 拍摄文件生成后的回调
6565
///
66+
/// Return `true` if it has handled arguments.
67+
/// 如果在回调中已经进行了处理,请返回 `true`
68+
///
6669
/// ### Notice about the implementation
67-
/// * After the callback is implemented, the default viewer page
68-
/// will not be pushed anymore.
70+
/// * After the callback is implemented and returned `true`,
71+
/// the default viewer page will not be presented anymore.
6972
///
7073
/// ### 在实现时需要注意
71-
/// * 实现该方法后,默认的的预览页面不会再出现
74+
/// * 实现了该方法且返回 `true` 后,默认的预览页面不会再出现
7275
/// {@endtemplate}
73-
typedef XFileCapturedCallback = void Function(XFile, CameraPickerViewType);
76+
typedef XFileCapturedCallback = bool Function(XFile, CameraPickerViewType);

lib/src/widgets/camera_picker.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,20 +646,23 @@ class CameraPickerState extends State<CameraPicker>
646646
return;
647647
}
648648
try {
649-
final XFile _file = await controller.takePicture();
649+
final XFile file = await controller.takePicture();
650650
// Delay disposing the controller to hold the preview.
651651
Future<void>.delayed(const Duration(milliseconds: 500), () {
652652
_controller?.dispose();
653653
safeSetState(() {
654654
_controller = null;
655655
});
656656
});
657-
if (config.onXFileCaptured != null) {
658-
config.onXFileCaptured!(_file, CameraPickerViewType.image);
657+
final bool? isCapturedFileHandled = config.onXFileCaptured?.call(
658+
file,
659+
CameraPickerViewType.image,
660+
);
661+
if (isCapturedFileHandled == true) {
659662
return;
660663
}
661664
final AssetEntity? entity = await _pushToViewer(
662-
file: _file,
665+
file: file,
663666
viewType: CameraPickerViewType.image,
664667
);
665668
if (entity != null) {
@@ -747,8 +750,11 @@ class CameraPickerState extends State<CameraPicker>
747750
if (controller.value.isRecordingVideo) {
748751
try {
749752
final XFile file = await controller.stopVideoRecording();
750-
if (config.onXFileCaptured != null) {
751-
config.onXFileCaptured!(file, CameraPickerViewType.video);
753+
final bool? isCapturedFileHandled = config.onXFileCaptured?.call(
754+
file,
755+
CameraPickerViewType.video,
756+
);
757+
if (isCapturedFileHandled == true) {
752758
return;
753759
}
754760
final AssetEntity? entity = await _pushToViewer(

0 commit comments

Comments
 (0)