From a799b15155cf55a8f68efabdb393571afa15aaad Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 26 Sep 2025 09:56:11 +0800 Subject: [PATCH] opt image crop Signed-off-by: bggRGjQaUbCoE --- .../publish/common_rich_text_pub_page.dart | 2 +- lib/pages/fav_create/view.dart | 79 ++++++++++--------- lib/pages/member_profile/view.dart | 60 ++++++++------ 3 files changed, 77 insertions(+), 64 deletions(-) diff --git a/lib/pages/common/publish/common_rich_text_pub_page.dart b/lib/pages/common/publish/common_rich_text_pub_page.dart index 8f103c516..a71e9d420 100644 --- a/lib/pages/common/publish/common_rich_text_pub_page.dart +++ b/lib/pages/common/publish/common_rich_text_pub_page.dart @@ -149,7 +149,7 @@ abstract class CommonRichTextPubPageState Future onCropImage(int index) async { late final colorScheme = ColorScheme.of(context); - CroppedFile? croppedFile = await ImageCropper().cropImage( + CroppedFile? croppedFile = await ImageCropper.platform.cropImage( sourcePath: pathList[index], uiSettings: [ AndroidUiSettings( diff --git a/lib/pages/fav_create/view.dart b/lib/pages/fav_create/view.dart index 22b74d8c9..b9cef9ca3 100644 --- a/lib/pages/fav_create/view.dart +++ b/lib/pages/fav_create/view.dart @@ -5,6 +5,7 @@ import 'package:PiliPlus/models_new/fav/fav_folder/list.dart'; import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/fav_utils.dart'; import 'package:PiliPlus/utils/image_utils.dart'; +import 'package:PiliPlus/utils/utils.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:flutter/material.dart'; @@ -115,44 +116,48 @@ class _CreateFavPageState extends State { imageQuality: 100, ); if (pickedFile != null && mounted) { - CroppedFile? croppedFile = await ImageCropper().cropImage( - sourcePath: pickedFile.path, - uiSettings: [ - AndroidUiSettings( - toolbarTitle: '裁剪', - toolbarColor: theme.colorScheme.secondaryContainer, - toolbarWidgetColor: theme.colorScheme.onSecondaryContainer, - statusBarLight: theme.colorScheme.brightness.isLight, - aspectRatioPresets: [CropAspectRatioPreset.ratio16x9], - lockAspectRatio: true, - hideBottomControls: true, - initAspectRatio: CropAspectRatioPreset.ratio16x9, - ), - IOSUiSettings( - title: '裁剪', - // aspectRatioPresets: [CropAspectRatioPreset.ratio16x9], - // aspectRatioLockEnabled: false, - // resetAspectRatioEnabled: false, - // aspectRatioPickerButtonHidden: true, - ), - ], - ); - if (croppedFile != null) { - MsgHttp.uploadImage( - path: croppedFile.path, - bucket: 'medialist', - dir: 'cover', - ).then((res) { - if (context.mounted) { - if (res['status']) { - _cover = res['data']['location']; - (context as Element).markNeedsBuild(); - } else { - SmartDialog.showToast(res['msg']); - } - } - }); + String imgPath = pickedFile.path; + if (Utils.isMobile) { + CroppedFile? croppedFile = await ImageCropper.platform.cropImage( + sourcePath: pickedFile.path, + uiSettings: [ + AndroidUiSettings( + toolbarTitle: '裁剪', + toolbarColor: theme.colorScheme.secondaryContainer, + toolbarWidgetColor: theme.colorScheme.onSecondaryContainer, + statusBarLight: theme.colorScheme.brightness.isLight, + aspectRatioPresets: [CropAspectRatioPreset.ratio16x9], + lockAspectRatio: true, + hideBottomControls: true, + initAspectRatio: CropAspectRatioPreset.ratio16x9, + ), + IOSUiSettings( + title: '裁剪', + // aspectRatioPresets: [CropAspectRatioPreset.ratio16x9], + // aspectRatioLockEnabled: false, + // resetAspectRatioEnabled: false, + // aspectRatioPickerButtonHidden: true, + ), + ], + ); + if (croppedFile != null) { + imgPath = croppedFile.path; + } } + MsgHttp.uploadImage( + path: imgPath, + bucket: 'medialist', + dir: 'cover', + ).then((res) { + if (context.mounted) { + if (res['status']) { + _cover = res['data']['location']; + (context as Element).markNeedsBuild(); + } else { + SmartDialog.showToast(res['msg']); + } + } + }); } } catch (e) { SmartDialog.showToast(e.toString()); diff --git a/lib/pages/member_profile/view.dart b/lib/pages/member_profile/view.dart index cba140b73..ca26941a9 100644 --- a/lib/pages/member_profile/view.dart +++ b/lib/pages/member_profile/view.dart @@ -488,31 +488,39 @@ class _EditProfilePageState extends State { SmartDialog.showToast('不能选GIF'); return; } - CroppedFile? croppedFile = await ImageCropper().cropImage( - sourcePath: pickedFile.path, - uiSettings: [ - AndroidUiSettings( - toolbarTitle: '裁剪', - toolbarColor: theme.colorScheme.secondaryContainer, - toolbarWidgetColor: theme.colorScheme.onSecondaryContainer, - statusBarLight: theme.colorScheme.brightness.isLight, - aspectRatioPresets: [CropAspectRatioPresetCustom()], - lockAspectRatio: true, - hideBottomControls: true, - cropStyle: CropStyle.circle, - initAspectRatio: CropAspectRatioPresetCustom(), - ), - IOSUiSettings( - title: '裁剪', - aspectRatioPresets: [CropAspectRatioPresetCustom()], - cropStyle: CropStyle.circle, - aspectRatioLockEnabled: true, - resetAspectRatioEnabled: false, - aspectRatioPickerButtonHidden: true, - ), - ], - ); - if (croppedFile != null) { + String? imagePath; + if (Utils.isMobile) { + CroppedFile? croppedFile = await ImageCropper.platform.cropImage( + sourcePath: pickedFile.path, + uiSettings: [ + AndroidUiSettings( + toolbarTitle: '裁剪', + toolbarColor: theme.colorScheme.secondaryContainer, + toolbarWidgetColor: theme.colorScheme.onSecondaryContainer, + statusBarLight: theme.colorScheme.brightness.isLight, + aspectRatioPresets: [CropAspectRatioPresetCustom()], + lockAspectRatio: true, + hideBottomControls: true, + cropStyle: CropStyle.circle, + initAspectRatio: CropAspectRatioPresetCustom(), + ), + IOSUiSettings( + title: '裁剪', + aspectRatioPresets: [CropAspectRatioPresetCustom()], + cropStyle: CropStyle.circle, + aspectRatioLockEnabled: true, + resetAspectRatioEnabled: false, + aspectRatioPickerButtonHidden: true, + ), + ], + ); + if (croppedFile != null) { + imagePath = croppedFile.path; + } + } else { + imagePath = pickedFile.path; + } + if (imagePath != null) { Request() .post( '/x/member/web/face/update', @@ -522,7 +530,7 @@ class _EditProfilePageState extends State { data: FormData.fromMap({ 'dopost': 'save', 'DisplayRank': 10000, - 'face': await MultipartFile.fromFile(croppedFile.path), + 'face': await MultipartFile.fromFile(imagePath), }), ) .then((res) {