Skip to content

Commit cd1bbbd

Browse files
authored
🐛 Correct behaviors when the access is limited (#392)
1 parent d39d74f commit cd1bbbd

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ that can be found in the LICENSE file. -->
1010

1111
- Allow overrides `viewAsset` in the `AssetPickerBuilderDelegate`. (#391)
1212

13+
### Fixes
14+
15+
- Correct behaviors when the access is limited on iOS. (#392)
16+
1317
## 8.1.4
1418

1519
### Fixes

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -800,34 +800,49 @@ class DefaultAssetPickerBuilderDelegate
800800
if (!isPermissionLimited) {
801801
return;
802802
}
803-
final PathWrapper<AssetPathEntity>? currentWrapper = provider.currentPath;
803+
isSwitchingPath.value = false;
804804
if (call.arguments is Map) {
805805
final Map<dynamic, dynamic> arguments =
806806
call.arguments as Map<dynamic, dynamic>;
807807
if (arguments['newCount'] == 0) {
808808
provider
809809
..currentAssets = <AssetEntity>[]
810810
..currentPath = null
811+
..selectedAssets = <AssetEntity>[]
811812
..hasAssetsToDisplay = false
812-
..isAssetsEmpty = true;
813+
..isAssetsEmpty = true
814+
..totalAssetsCount = 0
815+
..paths.clear();
813816
return;
814817
}
815-
if (currentWrapper == null) {
816-
await provider.getPaths();
817-
}
818818
}
819+
await provider.getPaths();
820+
provider.currentPath = provider.paths.first;
821+
final PathWrapper<AssetPathEntity>? currentWrapper = provider.currentPath;
819822
if (currentWrapper != null) {
820823
final AssetPathEntity newPath =
821824
await currentWrapper.path.obtainForNewProperties();
822825
final int assetCount = await newPath.assetCountAsync;
826+
final PathWrapper<AssetPathEntity> newPathWrapper =
827+
PathWrapper<AssetPathEntity>(
828+
path: newPath,
829+
assetCount: assetCount,
830+
);
823831
provider
824-
..currentPath = PathWrapper<AssetPathEntity>(path: newPath)
832+
..currentPath = newPathWrapper
825833
..hasAssetsToDisplay = assetCount != 0
826834
..isAssetsEmpty = assetCount == 0
827-
..totalAssetsCount = assetCount;
828-
isSwitchingPath.value = false;
835+
..totalAssetsCount = assetCount
836+
..getThumbnailFromPath(newPathWrapper);
829837
if (newPath.isAll) {
830838
await provider.getAssetsFromCurrentPath();
839+
final List<AssetEntity> entitiesShouldBeRemoved = <AssetEntity>[];
840+
for (final AssetEntity entity in provider.selectedAssets) {
841+
if (!provider.currentAssets.contains(entity)) {
842+
entitiesShouldBeRemoved.add(entity);
843+
}
844+
}
845+
entitiesShouldBeRemoved.forEach(provider.selectedAssets.remove);
831846
}
832847
}
833848
}
@@ -1395,7 +1410,7 @@ class DefaultAssetPickerBuilderDelegate
13951410

13961411
// Return actual length if the current path is all.
13971412
// 如果当前目录是全部内容,则返回实际的内容数量。
1398-
if (currentPathEntity?.isAll != true) {
1413+
if (currentPathEntity?.isAll != true && specialItem == null) {
13991414
return length;
14001415
}
14011416
switch (specialItemPosition) {
@@ -1706,14 +1721,13 @@ class DefaultAssetPickerBuilderDelegate
17061721
return UnconstrainedBox(
17071722
child: GestureDetector(
17081723
onTap: () {
1709-
if (provider.currentPath == null) {
1710-
return;
1711-
}
1712-
Feedback.forTap(context);
17131724
if (isPermissionLimited && provider.isAssetsEmpty) {
17141725
PhotoManager.presentLimited();
17151726
return;
17161727
}
1728+
if (provider.currentPath == null) {
1729+
return;
1730+
}
17171731
isSwitchingPath.value = !isSwitchingPath.value;
17181732
},
17191733
child: Container(

lib/src/provider/asset_picker_provider.dart

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ abstract class AssetPickerProvider<Asset, Path> extends ChangeNotifier {
133133
/// for the first asset under the path.
134134
/// 使用 [Map] 来保存路径下第一个资源的缩略图数据
135135
List<PathWrapper<Path>> get paths => _paths;
136-
final List<PathWrapper<Path>> _paths = <PathWrapper<Path>>[];
136+
List<PathWrapper<Path>> _paths = <PathWrapper<Path>>[];
137137

138138
/// Set thumbnail [data] for the specific [path].
139139
/// 为指定的路径设置缩略图数据
@@ -310,6 +310,8 @@ class DefaultAssetPickerProvider
310310
sizeConstraint: SizeConstraint(ignoreSize: true),
311311
),
312312
containsPathModified: sortPathsByModifiedDate,
313+
createTimeCond: DateTimeCond.def().copyWith(ignore: true),
314+
updateTimeCond: DateTimeCond.def().copyWith(ignore: true),
313315
);
314316

315317
// Merge user's filter option into base options if it's not null.
@@ -322,19 +324,9 @@ class DefaultAssetPickerProvider
322324
filterOption: options,
323325
);
324326

325-
for (final AssetPathEntity pathEntity in list) {
326-
final int index = _paths.indexWhere(
327-
(PathWrapper<AssetPathEntity> p) => p.path.id == pathEntity.id,
328-
);
329-
final PathWrapper<AssetPathEntity> wrapper = PathWrapper<AssetPathEntity>(
330-
path: pathEntity,
331-
);
332-
if (index == -1) {
333-
_paths.add(wrapper);
334-
} else {
335-
_paths[index] = wrapper;
336-
}
337-
}
327+
_paths = list
328+
.map((AssetPathEntity p) => PathWrapper<AssetPathEntity>(path: p))
329+
.toList();
338330
// Sort path using sort path delegate.
339331
Singleton.sortPathDelegate.sort(_paths);
340332
// Use sync method to avoid unnecessary wait.
@@ -357,11 +349,10 @@ class DefaultAssetPickerProvider
357349
size: pageSize,
358350
);
359351
if (page == 0) {
360-
_currentAssets = list;
361-
} else {
362-
_currentAssets.addAll(list);
352+
_currentAssets.clear();
363353
}
364-
_hasAssetsToDisplay = currentAssets.isNotEmpty;
354+
_currentAssets.addAll(list);
355+
_hasAssetsToDisplay = _currentAssets.isNotEmpty;
365356
notifyListeners();
366357
}
367358

0 commit comments

Comments
 (0)