Skip to content

Commit 7ca0935

Browse files
committed
🐛 Fix generic type when building indicators
1 parent 7432375 commit 7ca0935

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,29 @@ class FileAssetPickerBuilder
535535
);
536536
}
537537

538+
@override
539+
Widget loadingIndicator(BuildContext context) {
540+
return Selector<FileAssetPickerProvider, bool>(
541+
selector: (_, FileAssetPickerProvider p) => p.isAssetsEmpty,
542+
builder: (BuildContext context, bool isAssetsEmpty, Widget? w) {
543+
if (loadingIndicatorBuilder != null) {
544+
return loadingIndicatorBuilder!(context, isAssetsEmpty);
545+
}
546+
return Center(child: isAssetsEmpty ? emptyIndicator(context) : w);
547+
},
548+
child: Center(
549+
child: SizedBox.fromSize(
550+
size: Size.square(Screens.width / gridCount / 3),
551+
child: CircularProgressIndicator(
552+
valueColor: AlwaysStoppedAnimation<Color>(
553+
theme.iconTheme.color ?? Colors.grey,
554+
),
555+
),
556+
),
557+
),
558+
);
559+
}
560+
538561
@override
539562
Widget assetsGridBuilder(BuildContext context) {
540563
int totalCount = provider.currentAssets.length;

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
@@ -424,24 +434,6 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
424434
);
425435
}
426436

427-
/// Loading indicator.
428-
/// 加载指示器
429-
Widget loadingIndicator(BuildContext context) {
430-
return Selector<AssetPickerProvider<Asset, Path>, bool>(
431-
selector: (_, AssetPickerProvider<Asset, Path> p) => p.isAssetsEmpty,
432-
builder: (BuildContext context, bool isAssetsEmpty, Widget? w) {
433-
if (loadingIndicatorBuilder != null) {
434-
return loadingIndicatorBuilder!(context, isAssetsEmpty);
435-
}
436-
return Center(child: isAssetsEmpty ? emptyIndicator(context) : w);
437-
},
438-
child: PlatformProgressIndicator(
439-
color: theme.iconTheme.color,
440-
size: context.mediaQuery.size.width / gridCount / 3,
441-
),
442-
);
443-
}
444-
445437
/// Item widgets when the thumb data load failed.
446438
/// 资源缩略数据加载失败时使用的部件
447439
Widget failedItemBuilder(BuildContext context) {
@@ -1018,6 +1010,23 @@ class DefaultAssetPickerBuilderDelegate
10181010
);
10191011
}
10201012

1013+
@override
1014+
Widget loadingIndicator(BuildContext context) {
1015+
return Selector<DefaultAssetPickerProvider, bool>(
1016+
selector: (_, DefaultAssetPickerProvider p) => p.isAssetsEmpty,
1017+
builder: (BuildContext context, bool isAssetsEmpty, Widget? w) {
1018+
if (loadingIndicatorBuilder != null) {
1019+
return loadingIndicatorBuilder!(context, isAssetsEmpty);
1020+
}
1021+
return Center(child: isAssetsEmpty ? emptyIndicator(context) : w);
1022+
},
1023+
child: PlatformProgressIndicator(
1024+
color: theme.iconTheme.color,
1025+
size: context.mediaQuery.size.width / gridCount / 3,
1026+
),
1027+
);
1028+
}
1029+
10211030
@override
10221031
Widget assetsGridBuilder(BuildContext context) {
10231032
return Selector<DefaultAssetPickerProvider, AssetPathEntity?>(

0 commit comments

Comments
 (0)