selectAsset method
Future<void>
selectAsset(
- BuildContext context,
- AssetEntity asset,
- int index,
- bool selected,
override
The method to select assets. Delegates can implement this method to involve with predications, callbacks, etc. 选择资源的方法。自定义的 delegate 可以通过实现该方法,整合判断、回调等操作。
Implementation
@override
Future<void> selectAsset(
BuildContext context,
AssetEntity asset,
int index,
bool selected,
) async {
final bool? selectPredicateResult = await selectPredicate?.call(
context,
asset,
selected,
);
if (selectPredicateResult == false) {
return;
}
final DefaultAssetPickerProvider provider =
context.read<DefaultAssetPickerProvider>();
if (selected) {
provider.unSelectAsset(asset);
return;
}
if (isSingleAssetMode) {
provider.selectedAssets.clear();
}
provider.selectAsset(asset);
if (isSingleAssetMode && !isPreviewEnabled) {
Navigator.of(context).maybePop(provider.selectedAssets);
}
}