Flutter获取本地相册资源

photo_album_manager这是可以快速获取相册资源的插件,支持安卓和iOS;支持升序降序获取;支持图片视频分开获取;支持自定义数量获取;iOS端支持iCloud云端资源下载及下载进度回调等;

code

  /*获取相册资源(降序) maxCount 为null 获取全部资源*/
  static Future<List<AlbumModelEntity>> getDescAlbum({int maxCount}) async {
    List list = await _channel.invokeMethod('getDescAlbum', maxCount);
    List<AlbumModelEntity> album = List();
    list.forEach((item) => album.add(AlbumModelEntity.fromJson(item)));
    return album;
  }

  /*获取相册资源(升序) maxCount 为null 获取全部资源*/
  static Future<List<AlbumModelEntity>> getAscAlbum({int maxCount}) async {
    List list = await _channel.invokeMethod('getAscAlbum', maxCount);
    List<AlbumModelEntity> album = List();
    list.forEach((item) => album.add(AlbumModelEntity.fromJson(item)));
    return album;
  }

  /*获取相册图片资源(升序) maxCount 为null 获取全部资源*/
  static Future<List<AlbumModelEntity>> getAscAlbumImg({int maxCount}) async {
    List list = await _channel.invokeMethod('getAscAlbumImg', maxCount);
    List<AlbumModelEntity> album = List();
    list.forEach((item) => album.add(AlbumModelEntity.fromJson(item)));
    return album;
  }

  /*获取相册视频资源(升序) maxCount 为null 获取全部资源*/
  static Future<List<AlbumModelEntity>> getAscAlbumVideo({int maxCount}) async {
    List list = await _channel.invokeMethod('getAscAlbumVideo', maxCount);
    List<AlbumModelEntity> album = List();
    list.forEach((item) => album.add(AlbumModelEntity.fromJson(item)));
    return album;
  }

  /*获取相册图片资源(降序) maxCount 为null 获取全部资源*/
  static Future<List<AlbumModelEntity>> getDescAlbumImg({int maxCount}) async {
    List list = await _channel.invokeMethod('getDescAlbumImg', maxCount);
    List<AlbumModelEntity> album = List();
    list.forEach((item) => album.add(AlbumModelEntity.fromJson(item)));
    return album;
  }

  /*获取相册视频资源(降序) maxCount 为null 获取全部资源*/
  static Future<List<AlbumModelEntity>> getDescAlbumVideo(
      {int maxCount}) async {
    List list = await _channel.invokeMethod('getDescAlbumVideo', maxCount);
    List<AlbumModelEntity> album = List();
    list.forEach((item) => album.add(AlbumModelEntity.fromJson(item)));
    return album;
  }

  /*通过唯一标识localIdentifier 获取资源(原图、原视频)*/
  static Future<AlbumModelEntity> getOriginalImg(String localIdentifier,
      {void onProgress(double progress), void onError(String error)}) async {
    if (Platform.isIOS) {
      //监听加载进度
      _eventChannel.receiveBroadcastStream().listen((Object object) {
        if (object is double) {
          onProgress(object);
        } else {
          onError(object);
        }
      });
      List list =
          await _channel.invokeMethod('getOriginalResource', localIdentifier);
      if (list == null && list.length == 0) {
        onError("加载失败,请重试");
        return null;
      }
      AlbumModelEntity model = AlbumModelEntity.fromJson(list.first);
      return model;
    } else {
      List list =
          await _channel.invokeMethod('getOriginalResource', localIdentifier);
      List<AlbumModelEntity> album = List();
      list.forEach((item) => album.add(AlbumModelEntity.fromJson(item)));
      return album.first;
    }
  }

install

dependencies:
photo_album_manager: ^1.0.4

import

import 'package:album_manager/photo_album_manager.dart';

use

List<AlbumModelEntity> photos = await PhotoAlbumManager.getDescAlbumImg(maxCount: 100);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 天气即将入伏,感觉一天全日都是烈日高挂,不同以往的是,这个时期我不在办公室做着千篇一律不带喜好的事情,而是在家,...
    东南栖梧阅读 305评论 0 0
  • 作者/莫之 何处耕岩下,随緣度岁华。 青萝隐虫穴,紅袖沾仙葩。 石塊莫当虎,杯弓休作蛇。 不知浮世事,安逸乐生涯。
    江南莫之阅读 1,704评论 25 49
  • 春养肝,指春季养肝。春天在五行中属木,而人体的五脏之中肝也是属木性,因而春气通肝。在春天,肝气旺盛而升发,中医认为...
    胡顺娟阅读 867评论 0 0
  • 在这阳光明媚的星期天,我们宁海易善之家又迎来了第200期学经活动。童童和妈妈如约而至。 读过徐霞客游记的都知道,徐...
    严苧匀阅读 371评论 0 1
  • 昨天通知,小区用电负荷太大,停用一部电梯,给您带来出行不便,请谅解。必竟,停用谁家的空调,都不可能的。 ...
    买米阅读 309评论 2 6