getAssetsFromPath method

  1. @override
Future<void> getAssetsFromPath([
  1. int? page,
  2. AssetPathEntity? path
])
override

Get assets under the specific path entity. 获取指定路径下的资源

Implementation

@override
Future<void> getAssetsFromPath([int? page, AssetPathEntity? path]) {
  Future<void> run() async {
    final currentPage = page ?? currentAssetsListPage;
    final currentPath = path ?? this.currentPath!.path;
    final list = await currentPath.getAssetListPaged(
      page: currentPage,
      size: pageSize,
    );
    if (currentPage == 0) {
      _currentAssets.clear();
      _hasMoreToLoad = null;
    } else if (list.isEmpty) {
      _hasMoreToLoad = false;
    }
    _currentAssets.addAll(list);
    _hasAssetsToDisplay = _currentAssets.isNotEmpty;
    _isAssetsEmpty = _currentAssets.isEmpty;
    notifyListeners();
  }

  if (_getAssetsFromPathCompleter == null) {
    final completer = Completer<void>();
    _getAssetsFromPathCompleter = completer;
    run().then((r) {
      completer.complete();
    }).catchError((Object e, StackTrace s) {
      completer.completeError(e, s);
    }).whenComplete(() {
      _getAssetsFromPathCompleter = null;
    });
  }
  return _getAssetsFromPathCompleter!.future;
}