feat(image):修改相册中文名

This commit is contained in:
2026-07-06 16:01:52 +08:00
parent aa47bc97d5
commit 79455627f7
6 changed files with 209 additions and 195 deletions
+52 -16
View File
@@ -13,6 +13,22 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
class UploadImagesTool {
static String _assetPathNameBuilder(AssetPathEntity path) {
final locale =
Get.locale ?? WidgetsBinding.instance.platformDispatcher.locale;
if (locale.languageCode.toLowerCase() != 'zh') {
return path.name;
}
const systemPathNameMap = {
'Recent': '最近项目',
'Camera': '相机',
'Screenshots': '截屏',
'Downloads': '下载',
};
return systemPathNameMap[path.name] ?? path.name;
}
static uploadImagesTool({
String? oSSAccessKeyId,
String? policy,
@@ -139,7 +155,9 @@ class UploadImagesTool {
)
: CupertinoActionSheet(
title: const Text('上传图片'),
message: (max == null || max == 0) ? null : Text('请选择上传方式\n相册最多${max}'),
message: (max == null || max == 0)
? null
: Text('请选择上传方式\n相册最多${max}'),
actions: isAddOtherWidget != null
? <Widget>[
isAddOtherWidget,
@@ -153,7 +171,8 @@ class UploadImagesTool {
policy: policy ?? '',
callback: callback ?? '',
signature: signature ?? '',
chooseImages: (list) => chooseImages?.call(list),
chooseImages: (list) =>
chooseImages?.call(list),
);
Get.back();
},
@@ -169,7 +188,8 @@ class UploadImagesTool {
policy: policy ?? '',
callback: callback ?? '',
signature: signature ?? '',
chooseImages: (list) => chooseImages?.call(list),
chooseImages: (list) =>
chooseImages?.call(list),
);
Get.back();
},
@@ -186,7 +206,8 @@ class UploadImagesTool {
policy: policy ?? '',
callback: callback ?? '',
signature: signature ?? '',
chooseImages: (list) => chooseImages?.call(list),
chooseImages: (list) =>
chooseImages?.call(list),
);
Get.back();
},
@@ -203,7 +224,8 @@ class UploadImagesTool {
callback: callback ?? '',
signature: signature ?? '',
isShowLoading: isShowLoading,
chooseImages: (list) => chooseImages?.call(list),
chooseImages: (list) =>
chooseImages?.call(list),
);
Get.back();
},
@@ -231,11 +253,10 @@ class UploadImagesTool {
String? ossHost,
}) async {
XFile? file = await ImagePicker().pickImage(
source: ImageSource.camera,
maxHeight: 1080,
maxWidth: 1920,
imageQuality: 80
);
source: ImageSource.camera,
maxHeight: 1080,
maxWidth: 1920,
imageQuality: 80);
if (file == null) {
Get.back();
} else {
@@ -267,7 +288,11 @@ class UploadImagesTool {
if (isVideo == true) {
final List<AssetEntity>? result = await AssetPicker.pickAssets(
Get.context!,
pickerConfig: AssetPickerConfig(maxAssets: 1, requestType: RequestType.video),
pickerConfig: AssetPickerConfig(
maxAssets: 1,
requestType: RequestType.video,
pathNameBuilder: _assetPathNameBuilder,
),
);
final File? video = await result?.first.file;
String path = await saveNetworkImgGallery(
@@ -283,11 +308,16 @@ class UploadImagesTool {
chooseImages?.call([path]);
} else {
/// 创建临时目录
final Directory tempDir = Directory.systemTemp.createTempSync('compressed_images_');
final Directory tempDir =
Directory.systemTemp.createTempSync('compressed_images_');
final List<AssetEntity>? result = await AssetPicker.pickAssets(
Get.context!,
pickerConfig: AssetPickerConfig(maxAssets: max ?? 50),
pickerConfig: AssetPickerConfig(
maxAssets: max ?? 50,
pathNameBuilder: _assetPathNameBuilder,
),
);
/// 临时存储选中的图片
final List<XFile> selectedFiles = [];
if (result != null && result.isNotEmpty) {
@@ -296,16 +326,22 @@ class UploadImagesTool {
if (file != null) {
/// 获取文件扩展名
final String extension = file.absolute.path.split('.').last;
/// 压缩并保存到临时文件
final XFile? compressedFile = await FlutterImageCompress.compressAndGetFile(
file.absolute.path, '${tempDir.path}/${DateTime.now().millisecondsSinceEpoch}_compressed.$extension',
quality: 80, minWidth: 1920, minHeight: 1080);
final XFile? compressedFile =
await FlutterImageCompress.compressAndGetFile(
file.absolute.path,
'${tempDir.path}/${DateTime.now().millisecondsSinceEpoch}_compressed.$extension',
quality: 80,
minWidth: 1920,
minHeight: 1080);
if (compressedFile != null) {
selectedFiles.add(compressedFile);
}
}
}
}
/// 上传选中的图片
List<String> list = [];
for (var element in selectedFiles) {