selectAsset method

  1. @override
Future<void> selectAsset(
  1. BuildContext context,
  2. AssetEntity asset,
  3. int index,
  4. 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.maybeOf(context)?.maybePop(provider.selectedAssets);
  }
}