getPaths method

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

Get paths. 获取所有的资源路径

Implementation

@override
Future<void> getPaths() async {
  final PMFilter options;
  final PMFilter? fog = filterOptions;
  if (fog is FilterOptionGroup?) {
    // Initial base options.
    // Enable need title for audios to get proper display.
    final FilterOptionGroup newOptions = FilterOptionGroup(
      imageOption: const FilterOption(
        sizeConstraint: SizeConstraint(ignoreSize: true),
      ),
      audioOption: const FilterOption(
        needTitle: true,
        sizeConstraint: SizeConstraint(ignoreSize: true),
      ),
      containsPathModified: sortPathsByModifiedDate,
      createTimeCond: DateTimeCond.def().copyWith(ignore: true),
      updateTimeCond: DateTimeCond.def().copyWith(ignore: true),
    );
    // Merge user's filter options into base options if it's not null.
    if (fog != null) {
      newOptions.merge(fog);
    }
    options = newOptions;
  } else {
    options = fog;
  }

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

  _paths = list
      .map((AssetPathEntity p) => PathWrapper<AssetPathEntity>(path: p))
      .toList();
  // Sort path using sort path delegate.
  Singleton.sortPathDelegate.sort(_paths);
  // Use sync method to avoid unnecessary wait.
  _paths
    ..forEach(getAssetCountFromPath)
    ..forEach(getThumbnailFromPath);

  // Set first path entity as current path entity.
  if (_paths.isNotEmpty) {
    _currentPath ??= _paths.first;
  }
}