语言:英语| 中文
基于微信的UI的图像选择器(也带有视频和音频),用于扑朔迷离的项目。
当前基于以下UI的微信版将在随时更新之后更新8.0.51 UI设计。
要拍摄照片或视频以获取资产,请检查示例中的详细用法,然后转到Wechat_camera_picker。该包是一个独立的扩展名,可以结合使用。
请参阅《迁移指南》,以了解如何在破裂变化之间迁移。
该软件包仅保证在稳定版本的Flutter上工作。我们不会实时更新它以与其他扑波频道保持一致。
| 3.0 | 3.3 | 3.7 | 3.10 | 3.13 | 3.16 | |
|---|---|---|---|---|---|---|
| 8.9.0+ | ✅ | |||||
| 8.7.0+ | ✅ | |||||
| 8.5.0+ | ✅ | |||||
| 8.4.0+ | ✅ | |||||
| 8.0.0+ | ✅ | ✅ | ||||
| 7.3.0+ | ✅ | ✅ |
如果您在运行flutter pub get时遇到了resolve conflict错误,请使用dependency_overrides来修复它。
该软件包是由这些精美的包装构建的。
| 姓名 | 特征 |
|---|---|
| photo_manager | 资产的基本抽象和管理。 |
| Extended_Image | 预览具有预期行为的资产。 |
| 提供者 | 帮助管理选择器的相互作用状态。 |
| Video_player | 相应地播放视频和音频。 |
它们的实现应在包装中相对稳定。如果您在使用Picker时发现与他们有关的任何问题,请首先向我们的问题跟踪器提交问题。
AssetEntityhttpdioRecent与他人最新)File或Uint8List (RAWDATA)创建AssetEntityThemeData的完全可定制主题entity.file或AssetEntityImage图像。| 姓名 | 酒吧 | github |
|---|---|---|
| insta_assets_picker |
![]() | ![]() | ![]() |
|---|---|---|
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
在开始任何事情之前,请注意以下通知:
AssetEntityAssetPathEntity当您对相关的API和行为有疑问时,请查看Photo_Manager的API文档以获取更多详细信息。
大多数用法详细介绍了该示例。请在有任何疑问之前仔细浏览示例。
运行flutter pub add wechat_assets_picker ,或者手动添加wechat_assets_picker pubspec.yaml
dependencies :
wechat_assets_picker : ^latest_version最新的稳定版本是:
最新的开发版本是:
然后在您的代码中导入包:
import 'package:wechat_assets_picker/wechat_assets_picker.dart' ;使用软件包时,请将targetSdkVersion和compileSdkVersion升级到33 。否则,在Android 13上无法获取资产。
| 姓名 | 必需的 | 宣布 | 最大API级别 | 其他的 |
|---|---|---|---|---|
READ_EXTERNAL_STORAGE | 是的 | 是的 | 32 | |
WRITE_EXTERNAL_STORAGE | 不 | 不 | 29 | |
ACCESS_MEDIA_LOCATION | 是的* | 不 | N/A。 | 阅读exif时需要 |
READ_MEDIA_IMAGES | 是的* | 是的 | N/A。 | 阅读图像时需要 |
READ_MEDIA_VIDEO | 是的* | 是的 | N/A。 | 阅读视频时需要 |
READ_MEDIA_AUDIO | 是的* | 是的 | N/A。 | 阅读音频时需要 |
如果您针对Android SDK 33+,并且不需要加载照片,视频或音频,请考虑在应用程序中仅声明相关许可,更具体地说:
< manifest xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : tools = " http://schemas.android.com/tools "
package = " com.your.app " >
<!-- Requesting access to images and videos. -->
< uses-permission android : name = " android.permission.READ_MEDIA_IMAGES " />
< uses-permission android : name = " android.permission.READ_MEDIA_VIDEO " />
<!-- When your app has no need to access audio, remove it or comment it out. -->
<!-- <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> -->
</ manifest >ios/Podfile并进行相应更新。 platform :ios, '11.0'
#标题。Info.plist 。 <key>NSPhotoLibraryUsageDescription</key>
<string>Replace with your permission description.</string>
macos/Podfile并进行相应更新。 platform :osx , '10.15'#标题。macos/Runner.xcworkspace 。Info.plist 。 当您选择资产时,包裹将获得该Locale?从您的BuildContext ,然后返回当前语言的相应文本委托。确保您可以从BuildContext访问的小部件树中有一个有效的Locale 。否则,将使用默认的中国代表。
嵌入式文本代表语言为:
如果要使用自定义/固定文本委托,请通过AssetPickerConfig.textDelegate将其传递。
final List < AssetEntity > ? result = await AssetPicker . pickAssets (context);使用AssetPickerConfig进行更多的采摘行为。
final List < AssetEntity > ? result = await AssetPicker . pickAssets (
context,
pickerConfig : const AssetPickerConfig (),
); AssetPickerConfig的字段:
| 姓名 | 类型 | 描述 | 默认 |
|---|---|---|---|
| 选定 | List<AssetEntity>? | 选定的资产。防止重复选择。 | null |
| Maxassets | int | 采摘者可以选择的最大资产。 | 9 |
| 打页 | int? | 每页资产数量。必须是gridCount的倍数。 | 80 |
| 网格示威 | ThumbnailSize | 网格项目的缩略图大小。 | ThumbnailSize.square(200) |
| paththumbnailsize | ThumbnailSize | 路径选择器的缩略图大小。 | ThumbnailSize.square(80) |
| PreviewThumbNailsize | ThumbnailSize? | 预览查看器中的缩略图。 | null |
| requestType | RequestType | 请求类型选择器。 | RequestType.common |
| 特殊Pickertype | SpecialPickerType? | 提供了集成自定义选择器类型的选项。 | null |
| 保持Scrolloffset | bool | 选择器是否应保存滚动和弹出之间的滚动偏移。 | null |
| SortPathDelegate | SortPathDelegate<AssetPathEntity>? | 路径实体对选择器进行排序,并根据需要对路径进行排序。 | CommonSortPathDelegate |
| sortpathsbymodifieddate | bool | 是否允许排序代表使用FilterOptionGroup.containsPathModified对路径进行分类。 | false |
| 过滤器 | PMFilter? | 允许用户自定义资产过滤选项。 | null |
| gridcount | int | 在选择器中的网格计数。 | 4 |
| themecolor | Color? | 选择器的主要主题颜色。 | Color(0xff00bc56) |
| Pickertheme | ThemeData? | 选择器和观众的主题数据提供商。 | null |
| Textdelegate | AssetPickerTextDelegate? | 文本委派选择器,以自定义文本。 | AssetPickerTextDelegate() |
| 专业问题 | SpecialItemPosition | 允许用户在选择器中设置一个特殊物品,并设置多个位置。 | SpecialItemPosition.none |
| 专业人物 | SpecialItemBuilder? | 特殊物品的小部件构建器。 | null |
| 加载辅助构成器 | IndicatorBuilder? | 指示建筑商的加载状态。 | null |
| SelectPredicate | AssetSelectPredicate | 谓语是可以选择还是未选择资产。 | null |
| 应该reververtgrid | bool? | 资产网格是否应恢复。 | null |
| 限量性permissionOverlayPredicate | LimitedPermissionOverlayPredicate? | 谓词是否应显示有限的权限覆盖。 | null |
| PATHNAMEBUILDER | PathNameBuilder<AssetPathEntity>? | 使用给定路径实体构建自定义路径(专辑)名称。 | null |
| AssetschangeCallback | AssetsChangeCallback<AssetPathEntity>? | 当系统通知资产时,将调用回调。 | null |
| Assetschangerefreshpredicate | AssetsChangeRefreshPredicate<AssetPathEntity>? | 资产更改是否应使用给定的呼叫和当前选定路径刷新。 | null |
| 应该autooplaypreview | bool | 预览是否应自动播放。 | false |
maxAssets等于1 (又称单选模式)时,使用SpecialPickerType.noPreview将立即选择用户单击(按)并弹出的资产。limitedPermissionOverlayPredicate生命无坚持,如果您想忽略重新启动后的有限预览,则需要与自己的储蓄方法集成。在示例中,我们对包裹进行了多个常见用法。您都可以在此处和此处找到List<PickMethod> pickMethods ,该方法在多个选择和单个选择模式下提供了方法。资产将临时存储,并显示在页面下方。
AssetEntityImage和AssetEntityImageProvider可以显示图像和视频的拇指图像以及图像的原始数据。将其像常见的Image和ImageProvider一样使用。
AssetEntityImage (asset, isOriginal : false );或者:
Image (image : AssetEntityImageProvider (asset, isOriginal : false )); // Register callback.
AssetPicker . registerObserve ();
// Unregister callback.
AssetPicker . unregisterObserve ();AssetEntity有多种方法可以使用I/O相关方法上传AssetEntity 。请注意,I/O相关方法将消耗性能(通常是时间和内存),不应经常调用它们。
http http软件包:https://pub.dev/packages/http
http软件包使用MultipartFile来处理请求中的文件。
伪代码:
import 'package:http/http.dart' as http;
Future < void > upload () async {
final entity = await obtainYourEntity ();
final uri = Uri . https ( 'example.com' , 'create' );
final request = http. MultipartRequest ( 'POST' , uri)
..fields[ 'test_field' ] = 'test_value'
..files. add ( await multipartFileFromAssetEntity (entity));
final response = await request. send ();
if (response.statusCode == 200 ) {
print ( 'Uploaded!' );
}
}
Future <http. MultipartFile > multipartFileFromAssetEntity ( AssetEntity entity) async {
http. MultipartFile mf;
// Using the file path.
final file = await entity.file;
if (file == null ) {
throw StateError ( 'Unable to obtain file of the entity ${ entity . id }.' );
}
mf = await http. MultipartFile . fromPath ( 'test_file' , file.path);
// Using the bytes.
final bytes = await entity.originBytes;
if (bytes == null ) {
throw StateError ( 'Unable to obtain bytes of the entity ${ entity . id }.' );
}
mf = http. MultipartFile . fromBytes ( 'test_file' , bytes);
return mf;
}dio dio软件包:https://pub.dev/packages/dio
dio软件包还使用MultipartFile来处理请求中的文件。
伪代码:
import 'package:dio/dio.dart' as dio;
Future < void > upload () async {
final entity = await obtainYourEntity ();
final uri = Uri . https ( 'example.com' , 'create' );
final response = dio. Dio (). requestUri (
uri,
data : dio. FormData . fromMap ({
'test_field' : 'test_value' ,
'test_file' : await multipartFileFromAssetEntity (entity),
}),
);
print ( 'Uploaded!' );
}
Future <dio. MultipartFile > multipartFileFromAssetEntity ( AssetEntity entity) async {
dio. MultipartFile mf;
// Using the file path.
final file = await entity.file;
if (file == null ) {
throw StateError ( 'Unable to obtain file of the entity ${ entity . id }.' );
}
mf = await dio. MultipartFile . fromFile (file.path);
// Using the bytes.
final bytes = await entity.originBytes;
if (bytes == null ) {
throw StateError ( 'Unable to obtain bytes of the entity ${ entity . id }.' );
}
mf = dio. MultipartFile . fromBytes (bytes);
return mf;
}AssetPickerBuilderDelegate , AssetPickerViewerBuilderDelegate , AssetPickerProvider和AssetPickerViewerProvider都暴露了和不受欢迎。您可以扩展它们,并使用自己的类型使用通用类型<A: Asset, P: Path> ,然后实现抽象方法。
要知道如何完全自定义主题,小部件或布局。请参阅如何在示例的“自定义选择器”页面中自定义委托。
如果您发现实现可能对他人有用,则可以提交PRS以创建自己的实现。有关更多详细信息,请参见贡献自定义实施。
Recent与他人最新) Recent是Android上所有资产的修复专辑名称,因为所有资产的专辑不是实际的专辑,它仅代表所有媒体数据记录。
要在Android上解决该问题,请使用pathNameBuilder ,例如:
AssetPickerConfig (
pathNameBuilder : ( AssetPathEntity path) => switch (path) {
final p when p.isAll => '最近' ,
// You can apply similar conditions to other common paths.
_ => path.name,
},
)其他平台上的其他专辑或专辑(iOS/MACOS)将遵循配置的系统本地化和支持的本地化。 pathNameBuilder可用于所有专辑。
有关更多详细信息,请参见Photo_manager#561。
File或Uint8List (RAWDATA)创建AssetEntity为了将此软件包与相机拍摄或相关的内容相结合,有一个解决方案,即如何使用File或Uint8List对象创建AssetEntity 。
final File file = your_file; // Your `File` object
final String path = file.path;
final AssetEntity fileEntity = await PhotoManager .editor. saveImageWithPath (
path,
title : basename (path),
); // Saved in the device then create an AssetEntity
final Uint8List data = your_data; // Your `Uint8List` object
final AssetEntity imageEntity = await PhotoManager .editor. saveImage (
file.path,
title : 'title_with_extension.jpg' ,
); // Saved in the device then create an AssetEntity注意:如果您不想将文件保存在设备中,请尽可能地使用File进行操作。删除AssetEntity可能会导致系统弹出窗口显示:
final List < String > result = await PhotoManager .editor. deleteWithIds (
< String > [entity.id],
);有关更多详细信息,请参见photo_manager#from-raw-data和photo_manager#delete-entities。
W/Glide (21133): Failed to find GeneratedAppGlideModule.
You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler
in you application ana a @GlideModule annotated AppGlideModule implementation
or LibraryGlideModules will be silently ignored.
Glide需要注释以保持单身,防止实例和版本之间的冲突,因此,当照片管理器使用Glide实现图像功能时,该项目将定义其自己的AppGlideModule 。请参阅Glide生成的API文档以进行实施。
非常感谢这些出色的人(表情符号钥匙):
亚历克斯·李 ? ? ? ?门ch情该q情️? | Caijinglong ? | 马塞尔·施耐德(Marcel Schneider) ? ? | Ganlanshu0211 ? ? | Jasonhezz ? | Yaniv摇摇欲坠 ? ? ? | Avi-Yadav |
letalus ? ? | 藻类 ? | Nickolay Savchenko ? | 西格萨(Kosuke Saigusa) ? | 三闻书店 | didiosfaust ? | Xiejie ? |
艾哈迈德·马苏德(Ahmed Masoud) ? | Luomo-Pro 门ch情该q情️? | Paigupai ? | 穆罕默德·塔基·阿卜杜勒·阿齐兹(Muhammad Taqi Abdul Aziz) | 何锦余 ? | 莱昂·达德利克(Leon Dudlik) ? | 梅尔 ? |
DDDROP | nguyen phuc loi ? | Cevheri ? | Mirimhee ? | 阿莫斯 ? | Dimil Kalathiya | 加索尔·吴(Gasol Wu) ? |
该项目遵循全企业规范。欢迎任何形式的贡献!!
Intellij Idea的各个方面都是为了最大程度地提高开发人员的生产率。智能编码援助和人体工程学设计共同使发展不仅富有成效,而且使开发变得愉快。
感谢Jetbrains为Intellij Idea等IDE分配免费的开源许可证。
