getAssetPathList method

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

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

Implementation

@override
Future<void> getAssetPathList() async {
  // 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),
    ),
    containsPathModified: true,
  );

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

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

  // Sort path using sort path delegate.
  Constants.sortPathDelegate.sort(_list);

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

  // Set first path entity as current path entity.
  if (_pathEntityList.isNotEmpty) {
    _currentPathEntity ??= pathEntityList.keys.elementAt(0);
  }
}