Skip to content

Commit 0323ba0

Browse files
committed
⚡ Delay method calling with route duration.
1 parent ebb0a25 commit 0323ba0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/src/provider/asset_picker_provider.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ import 'package:wechat_assets_picker/wechat_assets_picker.dart';
1212
/// [ChangeNotifier] for assets picker.
1313
/// 资源选择器的 provider model
1414
class AssetPickerProvider extends ChangeNotifier {
15-
/// Call [getAssetList] when constructing.
16-
/// 构造时开始获取资源
15+
/// Call [getAssetList] with route duration when constructing.
16+
/// 构造时根据路由时长延时获取资源
1717
AssetPickerProvider({
1818
this.maxAssets = 9,
1919
this.pageSize = 320,
2020
this.pathThumbSize = 80,
2121
this.requestType = RequestType.image,
2222
List<AssetEntity> selectedAssets,
23+
Duration routeDuration,
2324
}) {
2425
if (selectedAssets?.isNotEmpty ?? false) {
2526
_selectedAssets = List<AssetEntity>.from(selectedAssets);
2627
}
27-
getAssetList();
28+
Future<void>.delayed(routeDuration).then(
29+
(dynamic _) => getAssetList(),
30+
);
2831
}
2932

3033
/// Maximum count for asset selection.

lib/src/widget/asset_picker.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AssetPicker extends StatelessWidget {
6464
Color themeColor = C.themeColor,
6565
TextDelegate textDelegate,
6666
Curve routeCurve = Curves.easeIn,
67-
Duration routeDuration = const Duration(milliseconds: 500),
67+
Duration routeDuration = const Duration(milliseconds: 300),
6868
}) async {
6969
assert(
7070
pageSize % gridCount == 0 || pageSize == null,
@@ -79,6 +79,7 @@ class AssetPicker extends StatelessWidget {
7979
pathThumbSize: pathThumbSize,
8080
selectedAssets: selectedAssets,
8181
requestType: requestType,
82+
routeDuration: routeDuration,
8283
);
8384
final Widget picker = AssetPicker(
8485
key: key,

0 commit comments

Comments
 (0)