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) {
  bool selectedAllAndNotSelected() =>
      !provider.selectedAssets.contains(asset) &&
      provider.selectedMaximumAssets;
  bool selectedPhotosAndIsVideo() =>
      isWeChatMoment &&
      asset.type == AssetType.video &&
      provider.selectedAssets.isNotEmpty;

  return Positioned.fill(
    child: GestureDetector(
      onTap: () async {
        // When we reached the maximum select count and the asset
        // is not selected, do nothing.
        // 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 (selectedAllAndNotSelected() || selectedPhotosAndIsVideo()) {
          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,
          shouldReversePreview: isAppleOS,
        );
        if (result != null) {
          Navigator.of(context).maybePop(result);
        }
      },
      child: Consumer<DefaultAssetPickerProvider>(
        builder: (_, DefaultAssetPickerProvider p, __) {
          final int index = p.selectedAssets.indexOf(asset);
          final bool selected = index != -1;
          return AnimatedContainer(
            duration: switchingPathDuration,
            color: selected
                ? theme.colorScheme.primary.withOpacity(.45)
                : Colors.black.withOpacity(.1),
            child: selected && !isSingleAssetMode
                ? Container(
                    alignment: AlignmentDirectional.topStart,
                    padding: const EdgeInsets.all(14),
                    child: ScaleText(
                      '${index + 1}',
                      style: TextStyle(
                        color: theme.textTheme.bodyText1?.color
                            ?.withOpacity(.75),
                        fontWeight: FontWeight.w600,
                        height: 1,
                      ),
                      maxScaleFactor: 1.4,
                    ),
                  )
                : const SizedBox.shrink(),
          );
        },
      ),
    ),
  );
}