previewButton method

  1. @override
Widget previewButton(
  1. BuildContext context
)
override

Preview button to preview selected assets. 预览已选资源的按钮

Implementation

@override
Widget previewButton(BuildContext context) {
  return Consumer<DefaultAssetPickerProvider>(
    builder: (_, DefaultAssetPickerProvider p, Widget? child) {
      return ValueListenableBuilder<bool>(
        valueListenable: isSwitchingPath,
        builder: (_, bool isSwitchingPath, __) => Semantics(
          enabled: p.isSelectedNotEmpty,
          focusable: !isSwitchingPath,
          hidden: isSwitchingPath,
          onTapHint: semanticsTextDelegate.sActionPreviewHint,
          child: child,
        ),
      );
    },
    child: Consumer<DefaultAssetPickerProvider>(
      builder: (context, DefaultAssetPickerProvider p, __) => GestureDetector(
        onTap: p.isSelectedNotEmpty
            ? () {
                viewAsset(context, null, p.selectedAssets.first);
              }
            : null,
        child: Selector<DefaultAssetPickerProvider, String>(
          selector: (_, DefaultAssetPickerProvider p) =>
              p.selectedDescriptions,
          builder: (BuildContext c, __, ___) => Padding(
            padding: const EdgeInsets.symmetric(vertical: 12),
            child: ScaleText(
              '${textDelegate.preview}'
              '${p.isSelectedNotEmpty ? ' (${p.selectedAssets.length})' : ''}',
              style: TextStyle(
                color: p.isSelectedNotEmpty
                    ? null
                    : c.textTheme.bodySmall?.color,
                fontSize: 17,
              ),
              maxScaleFactor: 1.2,
              semanticsLabel: '${semanticsTextDelegate.preview}'
                  '${p.isSelectedNotEmpty ? ' (${p.selectedAssets.length})' : ''}',
            ),
          ),
        ),
      ),
    ),
  );
}