Носитель в коде возвращает только изображения. У меня установлена последняя версия менеджера фотографий, а также я добавил необходимое разрешение в AndroidManifest.xml.
Вот результат, если мы распечатаем носитель:
I/flutter (10353): [AssetEntity(id: 1000000043, тип: AssetType.image), AssetEntity(id: 1000000042, тип: AssetType.image), AssetEntity(id: 1000000041, тип: AssetType.image), AssetEntity(id: 1000000040 , тип: AssetType.image), AssetEntity(id: 1000000039 , тип: AssetType.image), AssetEntity(id: 1000000038 , тип: AssetType.image), AssetEntity(id: 1000000037 , тип: AssetType.image), AssetEntity(id: 1000000036, тип: AssetType.image), AssetEntity(id: 1000000035, тип: AssetType.image), AssetEntity(id: 1000000033, тип: AssetType.image)]
Только изображения, хотя у меня есть видео.
МОЙ КОД
Код: Выделить всё
_fetchNewMedia() async {
lastPage = currentPage;
final PermissionRequestOption requestOption = PermissionRequestOption(
androidPermission: const AndroidPermission(
type: RequestType(1),
mediaLocation: false,
),
);
final PermissionState ps = await PhotoManager.requestPermissionExtend(
requestOption: requestOption,
);
print(ps);
final List paths = await PhotoManager.getAssetPathList(
hasAll: true,
type: RequestType.all,
);
print(paths);
AssetPathEntity recentAlbum = paths.firstWhere(
(album) => album.name == "Recent",
orElse: () => paths.first,
);
// Fetch media from the selected album
List media = await recentAlbum.getAssetListPaged(
page: currentPage,
size: 60,
);
print(media);
List videoMedia =
media.where((asset) => asset.type == AssetType.video).toList();
print(videoMedia);
List temp = [];
for (var asset in media) {
temp.add(
FutureBuilder(
future: asset.thumbnailDataWithSize(const ThumbnailSize(200, 200)),
builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Stack(
children: [
Positioned.fill(
child: Image.memory(
snapshot.data!,
fit: BoxFit.cover,
),
),
if (asset.type == AssetType.video)
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: EdgeInsets.only(right: 5, bottom: 5),
child: Icon(
Icons.videocam,
color: Colors.white,
),
),
),
],
);
}
return Container();
},
),
);
}
setState(() {
_mediaList.addAll(temp);
currentPage++;
});
}
Подробнее здесь: https://stackoverflow.com/questions/780 ... in-flutter
Мобильная версия