selectedBackdrop method

  1. @override
Widget selectedBackdrop(
  1. BuildContext context,
  2. int index,
  3. AssetEntity asset
)
override

Animated backdrop widget for items. 部件选中时的动画遮罩部件

Implementation

@override
Widget selectedBackdrop(BuildContext context, int index, AssetEntity asset) {
  return Positioned.fill(
    child: GestureDetector(
      onTap: () async {
        // When the special type is WeChat Moment, pictures and videos cannot
        // be selected at the same time. Video select should be banned if any
        // pictures are selected.
        if (isWeChatMoment &&
            asset.type == AssetType.video &&
            provider.selectedAssets.isNotEmpty) {
          return;
        }
        final List<AssetEntity> _current;
        final List<AssetEntity>? _selected;
        final int _index;
        if (isWeChatMoment) {
          if (asset.type == AssetType.video) {
            _current = <AssetEntity>[asset];
            _selected = null;
            _index = 0;
          } else {
            _current = provider.currentAssets
                .where((AssetEntity e) => e.type == AssetType.image)
                .toList();
            _selected = provider.selectedAssets;
            _index = _current.indexOf(asset);
          }
        } else {
          _current = provider.currentAssets;
          _selected = provider.selectedAssets;
          _index = index;
        }
        final List<AssetEntity>? result =
            await AssetPickerViewer.pushToViewer(
          context,
          currentIndex: _index,
          previewAssets: _current,
          themeData: theme,
          previewThumbSize: previewThumbSize,
          selectedAssets: _selected,
          selectorProvider: provider as DefaultAssetPickerProvider,
          specialPickerType: specialPickerType,
          maxAssets: provider.maxAssets,
        );
        if (result != null) {
          Navigator.of(context).pop(result);
        }
      },
      child: Selector<DefaultAssetPickerProvider, List<AssetEntity>>(
        selector: (_, DefaultAssetPickerProvider p) => p.selectedAssets,
        builder: (_, List<AssetEntity> selectedAssets, __) {
          final bool selected = selectedAssets.contains(asset);
          return AnimatedContainer(
            duration: switchingPathDuration,
            color: selected
                ? theme.colorScheme.primary.withOpacity(0.45)
                : Colors.black.withOpacity(0.1),
          );
        },
      ),
    ),
  );
}