照片
图片选择器,多选
支持 iOS iCloud
支持视频
使用 Flutter 作为 UI
如果您想构建自定义 UI,您只需要一个 API 来制作自定义 UI。可以使用 photo_manager 或 fork 该库来定制 UI。

安装
dependencies:
photo: $latest_version
导入
import 'package:photo/photo.dart';
import 'package:photo_manager/photo_manager.dart';
用法
void _pickImage() async {
List<AssetEntity> imgList = await PhotoPicker.pickAsset(
context: context,
// BuildContext requied
/// The following are optional parameters.
themeColor: Colors.green,
// the title color and bottom color
padding: 1.0,
// item padding
dividerColor: Colors.grey,
// divider color
disableColor: Colors.grey.shade300,
// the check box disable color
itemRadio: 0.88,
// the content item radio
maxSelected: 8,
// max picker image count
provider: I18nProvider.chinese,
// i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
rowCount: 5,
// item row count
textColor: Colors.white,
// text color
thumbSize: 150,
// preview thumb size , default is 64
sortDelegate: SortDelegate.common,
// default is common ,or you make custom delegate to sort your gallery
checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(
activeColor: Colors.white,
unselectedColor: Colors.white,
), // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
loadingDelegate:
this, // if you want to build custom loading widget,extends LoadingDelegate [see example/lib/main.dart]
pickType: type, // all/image/video
);
完整示例
关于 Android
Glide
Android 原生使用 Glide 来创建图片缩略图字节,版本为 4.8.0。
如果您的其他 Android 库使用了此库,并且版本不匹配,则需要编辑您的 Android 项目的 build.gradle 文件。
rootProject.allprojects {
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.github.bumptech.glide'
&& details.requested.name.contains('glide')) {
details.useVersion "4.8.0"
}
}
}
}
}
如果您使用 Proguard
请参阅 GitHub
关于 iOS
由于相册是隐私权限,您需要用户授权才能访问它。您必须修改 Runner 项目中的 Info.plist 文件。
如下所示
<key>NSPhotoLibraryUsageDescription</key>
<string>App need your agree, can visit your album</string>
Xcode 类似图片

构建错误
如果您遇到类似“framework 模块内包含非模块化头文件”的构建错误,请参阅 #10 或 Stack Overflow