@@ -359,6 +359,16 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
359359 /// Android设备的选择器布局
360360 Widget androidLayout (BuildContext context);
361361
362+ /// Loading indicator.
363+ /// 加载指示器
364+ ///
365+ /// Subclasses need to implement this due to the generic type limitation, and
366+ /// not all delegates use [AssetPickerProvider] .
367+ ///
368+ /// See also:
369+ /// - [DefaultAssetPickerBuilderDelegate.loadingIndicator] as an example.
370+ Widget loadingIndicator (BuildContext context);
371+
362372 /// GIF image type indicator.
363373 /// GIF 类型图片指示
364374 Widget gifIndicator (BuildContext context, Asset asset) {
@@ -414,29 +424,8 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
414424 );
415425 }
416426
417- /// Loading indicator.
418- /// 加载指示器
419- Widget loadingIndicator (BuildContext context) {
420- return Center (
421- child: Selector <AssetPickerProvider <Asset , Path >, bool >(
422- selector: (_, AssetPickerProvider <Asset , Path > p) => p.isAssetsEmpty,
423- builder: (BuildContext c, bool isAssetsEmpty, Widget ? w) {
424- if (loadingIndicatorBuilder != null ) {
425- return loadingIndicatorBuilder !(c, isAssetsEmpty);
426- }
427- if (isAssetsEmpty) {
428- return emptyIndicator (context);
429- }
430- return w! ;
431- },
432- child: PlatformProgressIndicator (
433- color: theme.iconTheme.color,
434- size: context.mediaQuery.size.width / gridCount / 3 ,
435- ),
436- ),
437- );
438- }
439-
427+ /// Indicator when no assets were found from the current path.
428+ /// 当前目录下无资源的显示
440429 Widget emptyIndicator (BuildContext context) {
441430 return ScaleText (
442431 textDelegate.emptyList,
@@ -1022,6 +1011,23 @@ class DefaultAssetPickerBuilderDelegate
10221011 );
10231012 }
10241013
1014+ @override
1015+ Widget loadingIndicator (BuildContext context) {
1016+ return Selector <DefaultAssetPickerProvider , bool >(
1017+ selector: (_, DefaultAssetPickerProvider p) => p.isAssetsEmpty,
1018+ builder: (BuildContext context, bool isAssetsEmpty, Widget ? w) {
1019+ if (loadingIndicatorBuilder != null ) {
1020+ return loadingIndicatorBuilder !(context, isAssetsEmpty);
1021+ }
1022+ return Center (child: isAssetsEmpty ? emptyIndicator (context) : w);
1023+ },
1024+ child: PlatformProgressIndicator (
1025+ color: theme.iconTheme.color,
1026+ size: context.mediaQuery.size.width / gridCount / 3 ,
1027+ ),
1028+ );
1029+ }
1030+
10251031 @override
10261032 Widget assetsGridBuilder (BuildContext context) {
10271033 return Selector <DefaultAssetPickerProvider , PathWrapper <AssetPathEntity >?>(
@@ -1048,8 +1054,7 @@ class DefaultAssetPickerBuilderDelegate
10481054 specialItem = null ;
10491055 }
10501056 if (totalCount == 0 && specialItem == null ) {
1051- return loadingIndicatorBuilder? .call (context, true ) ??
1052- loadingIndicator (context);
1057+ return loadingIndicator (context);
10531058 }
10541059 // Then we use the [totalCount] to calculate placeholders we need.
10551060 final int placeholderCount;
@@ -1536,24 +1541,6 @@ class DefaultAssetPickerBuilderDelegate
15361541 );
15371542 }
15381543
1539- @override
1540- Widget loadingIndicator (BuildContext context) {
1541- return Center (
1542- child: Selector <DefaultAssetPickerProvider , bool >(
1543- selector: (_, DefaultAssetPickerProvider p) => p.isAssetsEmpty,
1544- builder: (BuildContext context, bool isAssetsEmpty, __) {
1545- if (isAssetsEmpty) {
1546- return emptyIndicator (context);
1547- }
1548- return PlatformProgressIndicator (
1549- color: theme.iconTheme.color,
1550- size: context.mediaQuery.size.width / gridCount / 3 ,
1551- );
1552- },
1553- ),
1554- );
1555- }
1556-
15571544 /// While the picker is switching path, this will displayed.
15581545 /// If the user tapped on it, it'll collapse the list widget.
15591546 ///
0 commit comments