如何在Flutter中从图库中检索图像 [英] How can I retrieve images from Gallery in flutter

查看:71
本文介绍了如何在Flutter中从图库中检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Flutter中创建图像选择器,以便可以从图库中选择图像。

I am trying to make an image picker in Flutter where I can select image from gallery.

我不知道图像选择器的一些内置代码或库。

I don't know about some built-in code or library for an image picker.

推荐答案

我知道我可能会晚一点,但是您可以使用此库。

I know I might be a little bit late but you can use this library.

它返回图库和它的图库图像目前正在开发中,但应该可以在Android上完美运行,而对于iOS尚未完全实现。

It returns the gallery and the images of a gallery it's currently under development, but should work on Android perfectly, whereas for iOS it's not fully implemented yet.

List<PhoneAlbum> phoneAlbums = [];
final customImagePicker = CustomImagePicker();


Future<void> getGallery() async {
    try {
      await customImagePicker.getAlbums(callback: (msg) {
        setState(() {
          phoneAlbums = msg;
        });
      });
    } on PlatformException {}
  }

电话簿具有以下属性

String id;
String name;
String coverUri;
int photosCount;



要获取相册的照片:

To get photos of an album:

 List<PhonePhoto> images = [];

 final customImagePicker = CustomImagePicker();

Future<void> getPhotosOfGallery(String albumID) async {
    List<PhonePhoto> allImages = [];
    try {
      final cancelElement = await customImagePicker.getPhotosOfAlbum(albumID, callback: (msg) {
        print('The message is $msg');
      });
    } on PlatformException {}

    setState(() {
      images = allImages;
    });
  }

手机照片具有以下属性:

The phone photo has these properties:

 String id;
 String albumName;
 String photoUri;

这可以帮助您以自己喜欢的方式显示图像,并且很快就可以获取视频了以及分页(延迟加载)以提高性能

This helps you to display the images in the way you prefer, and very soon fetching video will be available, as well as pagination (Lazy loading) in order to improve the performance

https://pub.dev/packages/custom_image_picker

这篇关于如何在Flutter中从图库中检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆