onAssetsChanged method
Called when assets changed and obtained notifications from the OS. 系统发出资源变更的通知时调用的方法
Implementation
@override
Future<void> onAssetsChanged(MethodCall call, StateSetter setState) async {
if (!isPermissionLimited) {
return;
}
isSwitchingPath.value = false;
if (call.arguments is Map) {
final Map<dynamic, dynamic> arguments =
call.arguments as Map<dynamic, dynamic>;
if (arguments['newCount'] == 0) {
provider
..currentAssets = <AssetEntity>[]
..currentPath = null
..selectedAssets = <AssetEntity>[]
..hasAssetsToDisplay = false
..isAssetsEmpty = true
..totalAssetsCount = 0
..paths.clear();
return;
}
}
await provider.getPaths();
provider.currentPath = provider.paths.first;
final PathWrapper<AssetPathEntity>? currentWrapper = provider.currentPath;
if (currentWrapper != null) {
final AssetPathEntity newPath =
await currentWrapper.path.obtainForNewProperties();
final int assetCount = await newPath.assetCountAsync;
final PathWrapper<AssetPathEntity> newPathWrapper =
PathWrapper<AssetPathEntity>(
path: newPath,
assetCount: assetCount,
);
provider
..currentPath = newPathWrapper
..hasAssetsToDisplay = assetCount != 0
..isAssetsEmpty = assetCount == 0
..totalAssetsCount = assetCount
..getThumbnailFromPath(newPathWrapper);
if (newPath.isAll) {
await provider.getAssetsFromCurrentPath();
final List<AssetEntity> entitiesShouldBeRemoved = <AssetEntity>[];
for (final AssetEntity entity in provider.selectedAssets) {
if (!provider.currentAssets.contains(entity)) {
entitiesShouldBeRemoved.add(entity);
}
}
entitiesShouldBeRemoved.forEach(provider.selectedAssets.remove);
}
}
}