@@ -121,9 +121,19 @@ abstract class AssetPickerProvider<Asset, Path> extends ChangeNotifier {
121
121
notifyListeners ();
122
122
}
123
123
124
+ bool ? _hasMoreToLoad;
125
+
124
126
/// Whether more assets are waiting for a load.
125
127
/// 是否还有更多资源可以加载
126
- bool get hasMoreToLoad => _currentAssets.length < _totalAssetsCount! ;
128
+ bool get hasMoreToLoad {
129
+ if (_hasMoreToLoad case final bool value) {
130
+ return value;
131
+ }
132
+ if (_totalAssetsCount case final int count) {
133
+ return _currentAssets.length < count;
134
+ }
135
+ return true ;
136
+ }
127
137
128
138
/// The current page for assets list.
129
139
/// 当前加载的资源列表分页数
@@ -263,10 +273,7 @@ class DefaultAssetPickerProvider
263
273
}) {
264
274
Singleton .sortPathDelegate = sortPathDelegate ?? SortPathDelegate .common;
265
275
// Call [getAssetList] with route duration when constructing.
266
- Future <void >.delayed (initializeDelayDuration, () async {
267
- await getPaths ();
268
- await getAssetsFromCurrentPath ();
269
- });
276
+ Future <void >.delayed (initializeDelayDuration, getPaths);
270
277
}
271
278
272
279
@visibleForTesting
@@ -365,6 +372,8 @@ class DefaultAssetPickerProvider
365
372
if (_paths.isNotEmpty) {
366
373
_currentPath ?? = _paths.first;
367
374
}
375
+
376
+ await getAssetsFromCurrentPath ();
368
377
}
369
378
370
379
Completer <void >? _getAssetsFromPathCompleter;
@@ -380,18 +389,21 @@ class DefaultAssetPickerProvider
380
389
);
381
390
if (currentPage == 0 ) {
382
391
_currentAssets.clear ();
392
+ } else if (list.isEmpty) {
393
+ _hasMoreToLoad = false ;
383
394
}
384
395
_currentAssets.addAll (list);
385
396
_hasAssetsToDisplay = _currentAssets.isNotEmpty;
386
397
notifyListeners ();
387
398
}
388
399
389
400
if (_getAssetsFromPathCompleter == null ) {
390
- _getAssetsFromPathCompleter = Completer <void >();
391
- run ().then ((_) {
392
- _getAssetsFromPathCompleter! .complete ();
401
+ final completer = Completer <void >();
402
+ _getAssetsFromPathCompleter = completer;
403
+ run ().then ((r) {
404
+ completer.complete ();
393
405
}).catchError ((Object e, StackTrace s) {
394
- _getAssetsFromPathCompleter ! .completeError (e, s);
406
+ completer .completeError (e, s);
395
407
}).whenComplete (() {
396
408
_getAssetsFromPathCompleter = null ;
397
409
});
@@ -505,26 +517,6 @@ class DefaultAssetPickerProvider
505
517
isAssetsEmpty = true ;
506
518
return ;
507
519
}
508
- final PathWrapper <AssetPathEntity > wrapper = _currentPath! ;
509
- if (wrapper.assetCount == null ) {
510
- final int assetCount = await wrapper.path.assetCountAsync;
511
- // If the picker was disposed (#492), stop fetching the assets.
512
- if (! mounted) {
513
- return ;
514
- }
515
- if (_paths.isNotEmpty &&
516
- _currentPath != null &&
517
- _currentPath! .assetCount == null ) {
518
- _totalAssetsCount = assetCount;
519
- _isAssetsEmpty = assetCount == 0 ;
520
- _currentPath = wrapper.copyWith (assetCount: assetCount);
521
- notifyListeners ();
522
- } else if (_currentPath? .assetCount case final int count) {
523
- _totalAssetsCount = count;
524
- _isAssetsEmpty = count == 0 ;
525
- notifyListeners ();
526
- }
527
- }
528
520
await getAssetsFromPath (0 , currentPath! .path);
529
521
}
530
522
}
0 commit comments