opt image crop

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-09-26 09:56:11 +08:00
parent 33c8d69a58
commit a799b15155
3 changed files with 77 additions and 64 deletions

View File

@@ -149,7 +149,7 @@ abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
Future<void> onCropImage(int index) async { Future<void> onCropImage(int index) async {
late final colorScheme = ColorScheme.of(context); late final colorScheme = ColorScheme.of(context);
CroppedFile? croppedFile = await ImageCropper().cropImage( CroppedFile? croppedFile = await ImageCropper.platform.cropImage(
sourcePath: pathList[index], sourcePath: pathList[index],
uiSettings: [ uiSettings: [
AndroidUiSettings( AndroidUiSettings(

View File

@@ -5,6 +5,7 @@ import 'package:PiliPlus/models_new/fav/fav_folder/list.dart';
import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/fav_utils.dart'; import 'package:PiliPlus/utils/fav_utils.dart';
import 'package:PiliPlus/utils/image_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:cached_network_image/cached_network_image.dart';
import 'package:easy_debounce/easy_throttle.dart'; import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -115,44 +116,48 @@ class _CreateFavPageState extends State<CreateFavPage> {
imageQuality: 100, imageQuality: 100,
); );
if (pickedFile != null && mounted) { if (pickedFile != null && mounted) {
CroppedFile? croppedFile = await ImageCropper().cropImage( String imgPath = pickedFile.path;
sourcePath: pickedFile.path, if (Utils.isMobile) {
uiSettings: [ CroppedFile? croppedFile = await ImageCropper.platform.cropImage(
AndroidUiSettings( sourcePath: pickedFile.path,
toolbarTitle: '裁剪', uiSettings: [
toolbarColor: theme.colorScheme.secondaryContainer, AndroidUiSettings(
toolbarWidgetColor: theme.colorScheme.onSecondaryContainer, toolbarTitle: '裁剪',
statusBarLight: theme.colorScheme.brightness.isLight, toolbarColor: theme.colorScheme.secondaryContainer,
aspectRatioPresets: [CropAspectRatioPreset.ratio16x9], toolbarWidgetColor: theme.colorScheme.onSecondaryContainer,
lockAspectRatio: true, statusBarLight: theme.colorScheme.brightness.isLight,
hideBottomControls: true, aspectRatioPresets: [CropAspectRatioPreset.ratio16x9],
initAspectRatio: CropAspectRatioPreset.ratio16x9, lockAspectRatio: true,
), hideBottomControls: true,
IOSUiSettings( initAspectRatio: CropAspectRatioPreset.ratio16x9,
title: '裁剪', ),
// aspectRatioPresets: [CropAspectRatioPreset.ratio16x9], IOSUiSettings(
// aspectRatioLockEnabled: false, title: '裁剪',
// resetAspectRatioEnabled: false, // aspectRatioPresets: [CropAspectRatioPreset.ratio16x9],
// aspectRatioPickerButtonHidden: true, // aspectRatioLockEnabled: false,
), // resetAspectRatioEnabled: false,
], // aspectRatioPickerButtonHidden: true,
); ),
if (croppedFile != null) { ],
MsgHttp.uploadImage( );
path: croppedFile.path, if (croppedFile != null) {
bucket: 'medialist', imgPath = croppedFile.path;
dir: 'cover', }
).then((res) {
if (context.mounted) {
if (res['status']) {
_cover = res['data']['location'];
(context as Element).markNeedsBuild();
} else {
SmartDialog.showToast(res['msg']);
}
}
});
} }
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) { } catch (e) {
SmartDialog.showToast(e.toString()); SmartDialog.showToast(e.toString());

View File

@@ -488,31 +488,39 @@ class _EditProfilePageState extends State<EditProfilePage> {
SmartDialog.showToast('不能选GIF'); SmartDialog.showToast('不能选GIF');
return; return;
} }
CroppedFile? croppedFile = await ImageCropper().cropImage( String? imagePath;
sourcePath: pickedFile.path, if (Utils.isMobile) {
uiSettings: [ CroppedFile? croppedFile = await ImageCropper.platform.cropImage(
AndroidUiSettings( sourcePath: pickedFile.path,
toolbarTitle: '裁剪', uiSettings: [
toolbarColor: theme.colorScheme.secondaryContainer, AndroidUiSettings(
toolbarWidgetColor: theme.colorScheme.onSecondaryContainer, toolbarTitle: '裁剪',
statusBarLight: theme.colorScheme.brightness.isLight, toolbarColor: theme.colorScheme.secondaryContainer,
aspectRatioPresets: [CropAspectRatioPresetCustom()], toolbarWidgetColor: theme.colorScheme.onSecondaryContainer,
lockAspectRatio: true, statusBarLight: theme.colorScheme.brightness.isLight,
hideBottomControls: true, aspectRatioPresets: [CropAspectRatioPresetCustom()],
cropStyle: CropStyle.circle, lockAspectRatio: true,
initAspectRatio: CropAspectRatioPresetCustom(), hideBottomControls: true,
), cropStyle: CropStyle.circle,
IOSUiSettings( initAspectRatio: CropAspectRatioPresetCustom(),
title: '裁剪', ),
aspectRatioPresets: [CropAspectRatioPresetCustom()], IOSUiSettings(
cropStyle: CropStyle.circle, title: '裁剪',
aspectRatioLockEnabled: true, aspectRatioPresets: [CropAspectRatioPresetCustom()],
resetAspectRatioEnabled: false, cropStyle: CropStyle.circle,
aspectRatioPickerButtonHidden: true, aspectRatioLockEnabled: true,
), resetAspectRatioEnabled: false,
], aspectRatioPickerButtonHidden: true,
); ),
if (croppedFile != null) { ],
);
if (croppedFile != null) {
imagePath = croppedFile.path;
}
} else {
imagePath = pickedFile.path;
}
if (imagePath != null) {
Request() Request()
.post( .post(
'/x/member/web/face/update', '/x/member/web/face/update',
@@ -522,7 +530,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
data: FormData.fromMap({ data: FormData.fromMap({
'dopost': 'save', 'dopost': 'save',
'DisplayRank': 10000, 'DisplayRank': 10000,
'face': await MultipartFile.fromFile(croppedFile.path), 'face': await MultipartFile.fromFile(imagePath),
}), }),
) )
.then((res) { .then((res) {