selectIndicator method

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

Indicator for assets selected status. 资源是否已选的指示器

Implementation

@override
Widget selectIndicator(BuildContext context, int index, AssetEntity asset) {
  final double indicatorSize = context.mediaQuery.size.width / gridCount / 3;
  final Duration duration = switchingPathDuration * 0.75;
  return Selector<DefaultAssetPickerProvider, String>(
    selector: (_, DefaultAssetPickerProvider p) => p.selectedDescriptions,
    builder: (BuildContext context, String descriptions, __) {
      final bool selected = descriptions.contains(asset.toString());
      final Widget innerSelector = AnimatedContainer(
        duration: duration,
        width: indicatorSize / (isAppleOS ? 1.25 : 1.5),
        height: indicatorSize / (isAppleOS ? 1.25 : 1.5),
        padding: EdgeInsets.all(indicatorSize / 10),
        decoration: BoxDecoration(
          border: !selected
              ? Border.all(
                  color: context.themeData.unselectedWidgetColor,
                  width: indicatorSize / 25,
                )
              : null,
          color: selected ? themeColor : null,
          shape: BoxShape.circle,
        ),
        child: FittedBox(
          child: AnimatedSwitcher(
            duration: duration,
            reverseDuration: duration,
            child:
                selected ? const Icon(Icons.check) : const SizedBox.shrink(),
          ),
        ),
      );
      final Widget selectorWidget = GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () => selectAsset(context, asset, index, selected),
        child: Container(
          margin: EdgeInsets.all(indicatorSize / 4),
          width: isPreviewEnabled ? indicatorSize : null,
          height: isPreviewEnabled ? indicatorSize : null,
          alignment: AlignmentDirectional.topEnd,
          child: (!isPreviewEnabled && isSingleAssetMode && !selected)
              ? const SizedBox.shrink()
              : innerSelector,
        ),
      );
      if (isPreviewEnabled) {
        return PositionedDirectional(
          top: 0,
          end: 0,
          child: selectorWidget,
        );
      }
      return selectorWidget;
    },
  );
}