Skip to content

Commit 0e7c01e

Browse files
committed
🐛 Unify indicators usage to avoid accidentally indicator switching. (#344)
1 parent 8604525 commit 0e7c01e

File tree

4 files changed

+58
-69
lines changed

4 files changed

+58
-69
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ To know more about breaking changes, see [Migration Guide][].
1616
- Prevent race condition with paths. (#342)
1717
- Expose `sortPathsByModifiedDate`. (#343)
1818

19+
### Fixes
20+
21+
- Unify indicators usage to avoid accidentally indicator switching. (#344)
22+
1923
## 7.3.2
2024

2125
### Improvements

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,29 @@ class FileAssetPickerBuilder
540540
);
541541
}
542542

543+
@override
544+
Widget loadingIndicator(BuildContext context) {
545+
return Selector<FileAssetPickerProvider, bool>(
546+
selector: (_, FileAssetPickerProvider p) => p.isAssetsEmpty,
547+
builder: (BuildContext context, bool isAssetsEmpty, Widget? w) {
548+
if (loadingIndicatorBuilder != null) {
549+
return loadingIndicatorBuilder!(context, isAssetsEmpty);
550+
}
551+
return Center(child: isAssetsEmpty ? emptyIndicator(context) : w);
552+
},
553+
child: Center(
554+
child: SizedBox.fromSize(
555+
size: Size.square(Screens.width / gridCount / 3),
556+
child: CircularProgressIndicator(
557+
valueColor: AlwaysStoppedAnimation<Color>(
558+
theme.iconTheme.color ?? Colors.grey,
559+
),
560+
),
561+
),
562+
),
563+
);
564+
}
565+
543566
@override
544567
Widget assetsGridBuilder(BuildContext context) {
545568
int totalCount = provider.currentAssets.length;
@@ -770,31 +793,6 @@ class FileAssetPickerBuilder
770793
return RepaintBoundary(child: Image.file(asset, fit: BoxFit.cover));
771794
}
772795

773-
@override
774-
Widget loadingIndicator(BuildContext context) {
775-
return Center(
776-
child: Selector<FileAssetPickerProvider, bool>(
777-
selector: (_, FileAssetPickerProvider p) => p.isAssetsEmpty,
778-
builder: (_, bool isAssetsEmpty, __) {
779-
if (isAssetsEmpty) {
780-
return Text(textDelegate.emptyList);
781-
} else {
782-
return Center(
783-
child: SizedBox.fromSize(
784-
size: Size.square(Screens.width / gridCount / 3),
785-
child: CircularProgressIndicator(
786-
valueColor: AlwaysStoppedAnimation<Color>(
787-
theme.iconTheme.color ?? Colors.grey,
788-
),
789-
),
790-
),
791-
);
792-
}
793-
},
794-
),
795-
);
796-
}
797-
798796
@override
799797
Widget pathEntityListBackdrop(BuildContext context) {
800798
return ValueListenableBuilder<bool>(

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_assets_picker_demo
22
description: The demo project for the wechat_assets_picker package.
3-
version: 8.0.0+20
3+
version: 8.0.0+21
44
publish_to: none
55

66
environment:

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 30 additions & 43 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) {
@@ -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

Comments
 (0)