getAssetPathList method

  1. @override
Future<void> getAssetPathList()
override

Get assets path entities. 获取所有的资源路径

Implementation

@override
Future<void> getAssetPathList() async {

  // _pathEntityList.clear();

  // Initial base options.
  // Enable need title for audios and image to get proper display.
  final FilterOptionGroup options = FilterOptionGroup(
    imageOption: const FilterOption(
      needTitle: true,
      sizeConstraint: SizeConstraint(ignoreSize: true),
    ),
    audioOption: const FilterOption(
      needTitle: true,
      sizeConstraint: SizeConstraint(ignoreSize: true),
    ),
  );

  // Merge user's filter option into base options if it's not null.
  if (filterOptions != null) {
    options.merge(filterOptions!);
  }

  // Get All Photos
  final List<AssetPathEntity> _other = await PhotoManager.getAssetPathList(
    onlyAll: true,
    type: requestType,
    filterOption: options,
  );

  // Get all albums
  final List<AssetPathEntity> _list = await PhotoManager.getAssetPathList(
    type: requestType,
    filterOption: options,
  );


  // Remove recents from the list of albums
  _list.removeWhere((element) => element.name == (Platform.isIOS ? "Recents" : "Recent"));

  // Add recents into the first index
  _list.insert(0, _other.first);

  List<Future<void>> otherList = [];

  for (final AssetPathEntity pathEntity in _list) {
    // Use sync method to avoid unnecessary wait.
    if(_pathEntityList[pathEntity.id] == null){
      if (requestType != RequestType.audio) {
        final x = getFirstThumbFromPathEntity(pathEntity).then((Uint8List? data) {
          _pathEntityList[pathEntity.id] = Tuple2(pathEntity, data);
        });
        otherList.add(x);
      }
    }
  }

  await Future.wait(otherList);

  // Set first path entity as current path entity.
  if (_pathEntityList.isNotEmpty) {
    hasAlbumsToDisplay = true;
    notifyListeners();
  }
}