Skip to content

Commit 10dad6a

Browse files
authored
🥅 Raise more errors for non-synced paths (#545)
Fixes #528
1 parent 346fecb commit 10dad6a

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ that can be found in the LICENSE file. -->
1717

1818
- Fix previewing selected assets behavior.
1919
- Use `PermissionRequestOption` as much as possible.
20+
- Raise more errors for non-synced paths.
2021

2122
## 9.0.0-dev.2
2223

lib/src/provider/asset_picker_provider.dart

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,21 +495,35 @@ class DefaultAssetPickerProvider
495495
/// Get assets list from current path entity.
496496
/// 从当前已选路径获取资源列表
497497
Future<void> getAssetsFromCurrentPath() async {
498-
if (_currentPath == null || _paths.isEmpty) {
498+
if (_paths.isEmpty && _currentPath != null) {
499+
throw StateError('The current path is not synced with the empty paths.');
500+
}
501+
if (_paths.isNotEmpty && _currentPath == null) {
502+
throw StateError('The empty path is not synced with the current paths.');
503+
}
504+
if (_paths.isEmpty || _currentPath == null) {
499505
isAssetsEmpty = true;
500506
return;
501507
}
502508
final PathWrapper<AssetPathEntity> wrapper = _currentPath!;
503-
final int assetCount =
504-
wrapper.assetCount ?? await wrapper.path.assetCountAsync;
505-
// If the picker was disposed (#492), stop fetching the assets
506-
if (!mounted) {
507-
return;
508-
}
509-
totalAssetsCount = assetCount;
510-
isAssetsEmpty = assetCount == 0;
511509
if (wrapper.assetCount == null) {
512-
currentPath = _currentPath!.copyWith(assetCount: assetCount);
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+
}
513527
}
514528
await getAssetsFromPath(0, currentPath!.path);
515529
}

0 commit comments

Comments
 (0)