feat(picker): 统一安卓相册名称本地化
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_common/upload_image/ossUtil.dart';
|
import 'package:flutter_common/upload_image/ossUtil.dart';
|
||||||
|
import 'package:flutter_common/utils/asset_picker_localization.dart';
|
||||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
@@ -34,22 +35,6 @@ class _ImageCompressionTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class UploadImagesTool {
|
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({
|
static uploadImagesTool({
|
||||||
String? oSSAccessKeyId,
|
String? oSSAccessKeyId,
|
||||||
String? policy,
|
String? policy,
|
||||||
@@ -312,7 +297,8 @@ class UploadImagesTool {
|
|||||||
pickerConfig: AssetPickerConfig(
|
pickerConfig: AssetPickerConfig(
|
||||||
maxAssets: 1,
|
maxAssets: 1,
|
||||||
requestType: RequestType.video,
|
requestType: RequestType.video,
|
||||||
pathNameBuilder: _assetPathNameBuilder,
|
pathNameBuilder: (AssetPathEntity path) =>
|
||||||
|
AssetPickerLocalization.pathName(Get.context!, path),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final File? video = await result?.first.file;
|
final File? video = await result?.first.file;
|
||||||
@@ -335,7 +321,8 @@ class UploadImagesTool {
|
|||||||
Get.context!,
|
Get.context!,
|
||||||
pickerConfig: AssetPickerConfig(
|
pickerConfig: AssetPickerConfig(
|
||||||
maxAssets: max ?? 50,
|
maxAssets: max ?? 50,
|
||||||
pathNameBuilder: _assetPathNameBuilder,
|
pathNameBuilder: (AssetPathEntity path) =>
|
||||||
|
AssetPickerLocalization.pathName(Get.context!, path),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export 'video_batch_upload_config.dart';
|
export 'video_batch_upload_config.dart';
|
||||||
|
export 'video_batch_upload_service.dart';
|
||||||
export 'video_batch_upload_task.dart';
|
export 'video_batch_upload_task.dart';
|
||||||
export 'video_batch_uploader.dart';
|
export 'video_batch_uploader.dart';
|
||||||
export 'video_batch_upload_widgets.dart';
|
export 'video_batch_upload_widgets.dart';
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'dart:io';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_common/utils/asset_picker_localization.dart';
|
||||||
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
||||||
|
|
||||||
import 'video_batch_upload_config.dart';
|
import 'video_batch_upload_config.dart';
|
||||||
@@ -42,6 +43,8 @@ class VideoBatchUploadPicker {
|
|||||||
pickerConfig: AssetPickerConfig(
|
pickerConfig: AssetPickerConfig(
|
||||||
maxAssets: maxAssets,
|
maxAssets: maxAssets,
|
||||||
requestType: _requestType(assetType),
|
requestType: _requestType(assetType),
|
||||||
|
pathNameBuilder: (AssetPathEntity path) =>
|
||||||
|
AssetPickerLocalization.pathName(context, path),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (assets == null || assets.isEmpty) {
|
if (assets == null || assets.isEmpty) {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
||||||
|
|
||||||
|
abstract final class AssetPickerLocalization {
|
||||||
|
static String pathName(
|
||||||
|
BuildContext context,
|
||||||
|
AssetPathEntity path,
|
||||||
|
) {
|
||||||
|
final Locale locale = Localizations.maybeLocaleOf(context) ??
|
||||||
|
WidgetsBinding.instance.platformDispatcher.locale;
|
||||||
|
if (locale.languageCode.toLowerCase() != 'zh') {
|
||||||
|
return path.name;
|
||||||
|
}
|
||||||
|
if (path.isAll) {
|
||||||
|
return '最近项目';
|
||||||
|
}
|
||||||
|
|
||||||
|
const Map<String, String> systemPathNames = <String, String>{
|
||||||
|
'recent': '最近项目',
|
||||||
|
'recents': '最近项目',
|
||||||
|
'camera': '相机',
|
||||||
|
'camera roll': '相机',
|
||||||
|
'screenshot': '截屏',
|
||||||
|
'screenshots': '截屏',
|
||||||
|
'download': '下载',
|
||||||
|
'downloads': '下载',
|
||||||
|
'pictures': '图片',
|
||||||
|
'movies': '视频',
|
||||||
|
};
|
||||||
|
return systemPathNames[path.name.trim().toLowerCase()] ?? path.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user