Album Image 基于 photo_manager 包,概念上与 image_picker 类似,但提供了更具吸引力的界面,用于从设备图库中选择图像或视频,无论是 Android 还是 iOS。
特点
[✓] 选择图片
[✓] 选择视频
[✓] 选择多张图片/视频
[❌] 从相机拍摄图片或视频
演示图片
安装
- 此包仅在 Android 上进行了测试,请将
album_image: 0.0.1添加到您的pubspec.yaml文件中 - 导入
album_image
import 'package:album_image/album_image.dart';
入门
Android
在 AndroidMAnifest.xml 文件中添加 uses-permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
ios
在您的 info.plist 文件中添加此配置
<key>NSPhotoLibraryUsageDescription</key>
<string>Privacy - Photo Library Usage Description</string>
<key>NSMotionUsageDescription</key>
<string>Motion usage description</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>NSPhotoLibraryAddUsageDescription</string>
示例
import 'package:album_image/album_image.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Builder(builder: (context) {
final thumbnailQuality = MediaQuery.of(context).size.width ~/ 3;
return AlbumImagePicker(
onSelected: (items) {},
iconSelectionBuilder: (_, selected, index) {
if (selected) {
return CircleAvatar(
child: Text(
'${index + 1}',
style: const TextStyle(fontSize: 10, height: 1.4),
),
radius: 10,
);
}
return Container();
},
crossAxisCount: 3,
maxSelection: 4,
onSelectedMax: () {
print('Reach max');
},
albumBackGroundColor: Colors.white,
appBarHeight: 45,
itemBackgroundColor: Colors.grey[100]!,
appBarColor: Colors.white,
albumTextStyle: const TextStyle(color: Colors.black, fontSize: 14),
albumSubTextStyle:
const TextStyle(color: Colors.grey, fontSize: 10),
type: AlbumType.image,
closeWidget: const BackButton(
color: Colors.black,
),
thumbnailQuality: thumbnailQuality * 3,
);
}),
),
);
}
}

