pickImage method
When click image icon in chat.
example:
Implementation
// if (moreWidgetType == MoreWidgetType.picture) {
// selectImage(ImageSource.gallery);
// } else if (moreWidgetType == MoreWidgetType.camera) {
// selectImage(ImageSource.camera);
/// ```
// void selectImage(ImageSource imageSource) {
// MPickImageLogic.to.pickImage(imageSource, (String resultPath) {
// sendImageMessageHandle(resultPath);
// });
// }
/// ```
Future<void> pickImage(ImageSource imageSource,
void Function(String resultPath) onResult) async {
final PermissionStatus? status = imageSource == ImageSource.gallery
? await _requestPermissionsPhoto()
: await _requestPermissionsCamera();
if (status?.isGranted ?? false) {
try {
final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickImage(source: imageSource);
if (image != null) {
// Store the image path in the state
onResult(image.path);
} else {
// User canceled the picker
}
} catch (e, s) {
mLogger.e('pickImage::e::$e', stackTrace: s, error: e);
unawaited(mDialogConfirm('Notice'.tr, MStr.picturePermission, () async {
await openAppSettings();
}, tag: MAppDialogKey.confirmPicturePermission));
}
} else {
unawaited(mDialogConfirm('Notice'.tr, MStr.picturePermission, () async {
await openAppSettings();
}, tag: MAppDialogKey.confirmPicturePermission));
}
}