diff --git a/lib/src/delegates/asset_picker_builder_delegate.dart b/lib/src/delegates/asset_picker_builder_delegate.dart index 1c03810c..cf3c77fa 100644 --- a/lib/src/delegates/asset_picker_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_builder_delegate.dart @@ -1873,32 +1873,15 @@ class DefaultAssetPickerBuilderDelegate end: 20, ), child: ExcludeSemantics( - child: Row( - children: [ - Flexible( - child: Padding( - padding: const EdgeInsetsDirectional.only( - end: 10, - ), - child: ScaleText( - name, - style: const TextStyle(fontSize: 17), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - ), + child: ScaleText.rich( + [ + TextSpan(text: name), if (semanticsCount != null) - ScaleText( - '($semanticsCount)', - style: TextStyle( - color: theme.textTheme.bodySmall?.color, - fontSize: 17, - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), + TextSpan(text: ' ($semanticsCount)'), ], + style: const TextStyle(fontSize: 17), + maxLines: 1, + overflow: TextOverflow.ellipsis, ), ), ), diff --git a/lib/src/provider/asset_picker_provider.dart b/lib/src/provider/asset_picker_provider.dart index 3a726336..b32856ef 100644 --- a/lib/src/provider/asset_picker_provider.dart +++ b/lib/src/provider/asset_picker_provider.dart @@ -121,9 +121,19 @@ abstract class AssetPickerProvider extends ChangeNotifier { notifyListeners(); } + bool? _hasMoreToLoad; + /// Whether more assets are waiting for a load. /// 是否还有更多资源可以加载 - bool get hasMoreToLoad => _currentAssets.length < _totalAssetsCount!; + bool get hasMoreToLoad { + if (_hasMoreToLoad case final bool value) { + return value; + } + if (_totalAssetsCount case final int count) { + return _currentAssets.length < count; + } + return true; + } /// The current page for assets list. /// 当前加载的资源列表分页数 @@ -263,10 +273,7 @@ class DefaultAssetPickerProvider }) { Singleton.sortPathDelegate = sortPathDelegate ?? SortPathDelegate.common; // Call [getAssetList] with route duration when constructing. - Future.delayed(initializeDelayDuration, () async { - await getPaths(); - await getAssetsFromCurrentPath(); - }); + Future.delayed(initializeDelayDuration, getPaths); } @visibleForTesting @@ -365,6 +372,8 @@ class DefaultAssetPickerProvider if (_paths.isNotEmpty) { _currentPath ??= _paths.first; } + + await getAssetsFromCurrentPath(); } Completer? _getAssetsFromPathCompleter; @@ -380,6 +389,8 @@ class DefaultAssetPickerProvider ); if (currentPage == 0) { _currentAssets.clear(); + } else if (list.isEmpty) { + _hasMoreToLoad = false; } _currentAssets.addAll(list); _hasAssetsToDisplay = _currentAssets.isNotEmpty; @@ -387,11 +398,12 @@ class DefaultAssetPickerProvider } if (_getAssetsFromPathCompleter == null) { - _getAssetsFromPathCompleter = Completer(); - run().then((_) { - _getAssetsFromPathCompleter!.complete(); + final completer = Completer(); + _getAssetsFromPathCompleter = completer; + run().then((r) { + completer.complete(); }).catchError((Object e, StackTrace s) { - _getAssetsFromPathCompleter!.completeError(e, s); + completer.completeError(e, s); }).whenComplete(() { _getAssetsFromPathCompleter = null; }); @@ -499,18 +511,6 @@ class DefaultAssetPickerProvider isAssetsEmpty = true; return; } - final PathWrapper wrapper = _currentPath!; - final int assetCount = - wrapper.assetCount ?? await wrapper.path.assetCountAsync; - // If the picker was disposed (#492), stop fetching the assets - if (!mounted) { - return; - } - totalAssetsCount = assetCount; - isAssetsEmpty = assetCount == 0; - if (wrapper.assetCount == null) { - currentPath = _currentPath!.copyWith(assetCount: assetCount); - } await getAssetsFromPath(0, currentPath!.path); } }