From 18ca4c408221248916809b9b9aa016bb38732c98 Mon Sep 17 00:00:00 2001 From: yujune Date: Fri, 16 Aug 2024 14:43:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8Add=20onPicked=20callback=20when?= =?UTF-8?q?=20asset=20entity=20is=20generated.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/constants/config.dart | 6 ++++++ lib/src/states/camera_picker_state.dart | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/src/constants/config.dart b/lib/src/constants/config.dart index 9095e18..843d10a 100644 --- a/lib/src/constants/config.dart +++ b/lib/src/constants/config.dart @@ -5,6 +5,7 @@ import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:photo_manager/photo_manager.dart'; import '../delegates/camera_picker_text_delegate.dart'; import 'type_defs.dart'; @@ -42,6 +43,7 @@ final class CameraPickerConfig { this.onError, this.onXFileCaptured, this.onMinimumRecordDurationNotMet, + this.onPicked, }) : assert( enableRecording == true || onlyEnableRecording != true, 'Recording mode error.', @@ -165,4 +167,8 @@ final class CameraPickerConfig { /// The callback when the recording is not met the minimum recording duration. /// 录制时长未达到最小时长时的回调方法。 final VoidCallback? onMinimumRecordDurationNotMet; + + /// The callback when picture is taken or video is recorded. + /// 拍照或录像完成时的回调方法。 + final Function(AssetEntity)? onPicked; } diff --git a/lib/src/states/camera_picker_state.dart b/lib/src/states/camera_picker_state.dart index e42f636..e0e44dc 100644 --- a/lib/src/states/camera_picker_state.dart +++ b/lib/src/states/camera_picker_state.dart @@ -17,10 +17,10 @@ import 'package:sensors_plus/sensors_plus.dart'; import 'package:wechat_picker_library/wechat_picker_library.dart'; import '../constants/config.dart'; -import '../internals/singleton.dart'; import '../constants/enums.dart'; import '../delegates/camera_picker_text_delegate.dart'; import '../internals/methods.dart'; +import '../internals/singleton.dart'; import '../widgets/camera_focus_point.dart'; import '../widgets/camera_picker.dart'; import '../widgets/camera_picker_viewer.dart'; @@ -926,7 +926,12 @@ class CameraPickerState extends State viewType: CameraPickerViewType.image, ); if (entity != null) { - Navigator.of(context).pop(entity); + if (pickerConfig.onPicked case final onPicked?) { + await controller.resumePreview(); + onPicked(entity); + } else { + Navigator.of(context).pop(entity); + } return; } wrapControllerMethod( @@ -1056,7 +1061,12 @@ class CameraPickerState extends State viewType: CameraPickerViewType.video, ); if (entity != null) { - Navigator.of(context).pop(entity); + if (pickerConfig.onPicked case final onPicked?) { + await controller.resumePreview(); + onPicked(entity); + } else { + Navigator.of(context).pop(entity); + } } else { await controller.resumePreview(); } From d95ac8be3b1fb1fa6113c4a99094595e9e9b8c20 Mon Sep 17 00:00:00 2001 From: yujune Date: Fri, 16 Aug 2024 15:02:19 +0800 Subject: [PATCH 2/5] Add onPicked readme. --- README-ZH.md | 1 + README.md | 1 + lib/src/constants/config.dart | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README-ZH.md b/README-ZH.md index d7fef4e..c27779c 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -206,6 +206,7 @@ final AssetEntity? entity = await CameraPicker.pickFromCamera( | onError | `CameraErrorHandler?` | 拍摄照片过程中的自定义错误处理 | null | | onXFileCaptured | `XFileCapturedCallback?` | 拍摄文件生成后的回调 | null | | onMinimumRecordDurationNotMet | `VoidCallback?` | 录制时长未达到最小时长时的回调方法 | null | +| onPicked | `Function(AssetEntity)?` | 拍照或录像确认时的回调方法。 | null | ### 使用自定义的 `State` diff --git a/README.md b/README.md index bcf7e6d..b62921e 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,7 @@ Fields in `CameraPickerConfig`: | onError | `CameraErrorHandler?` | The error handler when any error occurred during the picking process. | null | | onXFileCaptured | `XFileCapturedCallback?` | The callback type definition when the XFile is captured by the camera. | null | | onMinimumRecordDurationNotMet | `VoidCallback?` | The callback when the recording is not met the minimum recording duration. | null | +| onPicked | `Function(AssetEntity)?` | The callback when picture is taken or video is confirmed. | null | ### Using custom `State`s diff --git a/lib/src/constants/config.dart b/lib/src/constants/config.dart index 843d10a..43979ac 100644 --- a/lib/src/constants/config.dart +++ b/lib/src/constants/config.dart @@ -168,7 +168,7 @@ final class CameraPickerConfig { /// 录制时长未达到最小时长时的回调方法。 final VoidCallback? onMinimumRecordDurationNotMet; - /// The callback when picture is taken or video is recorded. - /// 拍照或录像完成时的回调方法。 + /// The callback when picture is taken or video is confirmed. + /// 拍照或录像确认时的回调方法。 final Function(AssetEntity)? onPicked; } From a175e0f9529b17055731099d708198fce1e20050 Mon Sep 17 00:00:00 2001 From: yujune Date: Mon, 9 Sep 2024 10:24:53 +0800 Subject: [PATCH 3/5] Rename onPick to onPickConfirmed. --- README-ZH.md | 2 +- README.md | 2 +- lib/src/constants/config.dart | 4 ++-- lib/src/states/camera_picker_state.dart | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README-ZH.md b/README-ZH.md index c27779c..24cf247 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -206,7 +206,7 @@ final AssetEntity? entity = await CameraPicker.pickFromCamera( | onError | `CameraErrorHandler?` | 拍摄照片过程中的自定义错误处理 | null | | onXFileCaptured | `XFileCapturedCallback?` | 拍摄文件生成后的回调 | null | | onMinimumRecordDurationNotMet | `VoidCallback?` | 录制时长未达到最小时长时的回调方法 | null | -| onPicked | `Function(AssetEntity)?` | 拍照或录像确认时的回调方法。 | null | +| onPickConfirmed | `void Function(AssetEntity)?` | 拍照或录像确认时的回调方法。 | null | ### 使用自定义的 `State` diff --git a/README.md b/README.md index b62921e..91c7db2 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ Fields in `CameraPickerConfig`: | onError | `CameraErrorHandler?` | The error handler when any error occurred during the picking process. | null | | onXFileCaptured | `XFileCapturedCallback?` | The callback type definition when the XFile is captured by the camera. | null | | onMinimumRecordDurationNotMet | `VoidCallback?` | The callback when the recording is not met the minimum recording duration. | null | -| onPicked | `Function(AssetEntity)?` | The callback when picture is taken or video is confirmed. | null | +| onPickConfirmed | `void Function(AssetEntity)?` | The callback when picture is taken or video is confirmed. | null | ### Using custom `State`s diff --git a/lib/src/constants/config.dart b/lib/src/constants/config.dart index 43979ac..fd176a8 100644 --- a/lib/src/constants/config.dart +++ b/lib/src/constants/config.dart @@ -43,7 +43,7 @@ final class CameraPickerConfig { this.onError, this.onXFileCaptured, this.onMinimumRecordDurationNotMet, - this.onPicked, + this.onPickConfirmed, }) : assert( enableRecording == true || onlyEnableRecording != true, 'Recording mode error.', @@ -170,5 +170,5 @@ final class CameraPickerConfig { /// The callback when picture is taken or video is confirmed. /// 拍照或录像确认时的回调方法。 - final Function(AssetEntity)? onPicked; + final void Function(AssetEntity)? onPickConfirmed; } diff --git a/lib/src/states/camera_picker_state.dart b/lib/src/states/camera_picker_state.dart index e0e44dc..f24cf5d 100644 --- a/lib/src/states/camera_picker_state.dart +++ b/lib/src/states/camera_picker_state.dart @@ -926,9 +926,9 @@ class CameraPickerState extends State viewType: CameraPickerViewType.image, ); if (entity != null) { - if (pickerConfig.onPicked case final onPicked?) { + if (pickerConfig.onPickConfirmed case final onPickConfirmed?) { await controller.resumePreview(); - onPicked(entity); + onPickConfirmed(entity); } else { Navigator.of(context).pop(entity); } @@ -1061,9 +1061,9 @@ class CameraPickerState extends State viewType: CameraPickerViewType.video, ); if (entity != null) { - if (pickerConfig.onPicked case final onPicked?) { + if (pickerConfig.onPickConfirmed case final onPickConfirmed?) { await controller.resumePreview(); - onPicked(entity); + onPickConfirmed(entity); } else { Navigator.of(context).pop(entity); } From cb6440a455353c9ef8048c7c8eefdf4bf715c3cc Mon Sep 17 00:00:00 2001 From: yujune Date: Mon, 9 Sep 2024 11:11:28 +0800 Subject: [PATCH 4/5] Return only when pop. --- lib/src/states/camera_picker_state.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/src/states/camera_picker_state.dart b/lib/src/states/camera_picker_state.dart index f24cf5d..862d0b2 100644 --- a/lib/src/states/camera_picker_state.dart +++ b/lib/src/states/camera_picker_state.dart @@ -927,12 +927,10 @@ class CameraPickerState extends State ); if (entity != null) { if (pickerConfig.onPickConfirmed case final onPickConfirmed?) { - await controller.resumePreview(); onPickConfirmed(entity); } else { - Navigator.of(context).pop(entity); + return Navigator.of(context).pop(entity); } - return; } wrapControllerMethod( 'setFocusMode', From 23d055dd7e4b5735ffb2394b70b026afb39a40a9 Mon Sep 17 00:00:00 2001 From: Tee Yu June <56582497+yujune@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:58:42 +0800 Subject: [PATCH 5/5] Update onPickConfirmed comment. Co-authored-by: Alex Li --- lib/src/constants/config.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/constants/config.dart b/lib/src/constants/config.dart index fd176a8..3e4d499 100644 --- a/lib/src/constants/config.dart +++ b/lib/src/constants/config.dart @@ -168,7 +168,7 @@ final class CameraPickerConfig { /// 录制时长未达到最小时长时的回调方法。 final VoidCallback? onMinimumRecordDurationNotMet; - /// The callback when picture is taken or video is confirmed. + /// The callback when the picture or the video is confirmed as picked. /// 拍照或录像确认时的回调方法。 final void Function(AssetEntity)? onPickConfirmed; }