confirmButton method

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

It'll pop with AssetPickerProvider.selectedAssets when there are any assets were chosen. Then, the assets picker will pop too. 当有资源已选时,点击按钮将把已选资源通过路由返回。 资源选择器将识别并一同返回。

Implementation

@override
Widget confirmButton(BuildContext context) {
  return CNP<AssetPickerViewerProvider<AssetEntity>?>.value(
    value: provider,
    child: Consumer<AssetPickerViewerProvider<AssetEntity>?>(
      builder: (_, AssetPickerViewerProvider<AssetEntity>? provider, __) {
        assert(
          isWeChatMoment || provider != null,
          'Viewer provider must not be null '
          'when the special type is not WeChat moment.',
        );
        Future<void> onPressed() async {
          if (isWeChatMoment && hasVideo) {
            Navigator.maybeOf(context)?.pop(<AssetEntity>[currentAsset]);
            return;
          }
          if (provider!.isSelectedNotEmpty) {
            Navigator.maybeOf(context)?.pop(provider.currentlySelectedAssets);
            return;
          }
          if (await onChangingSelected(context, currentAsset, false)) {
            Navigator.maybeOf(context)?.pop(
              selectedAssets ?? <AssetEntity>[currentAsset],
            );
          }
        }

        String buildText() {
          if (isWeChatMoment && hasVideo) {
            return textDelegate.confirm;
          }
          if (provider!.isSelectedNotEmpty) {
            return '${textDelegate.confirm}'
                ' (${provider.currentlySelectedAssets.length}'
                '/'
                '${selectorProvider!.maxAssets})';
          }
          return textDelegate.confirm;
        }

        final isButtonEnabled = provider == null ||
            previewAssets.isEmpty ||
            (selectedAssets?.isNotEmpty ?? false);
        return MaterialButton(
          minWidth:
              (isWeChatMoment && hasVideo) || provider!.isSelectedNotEmpty
                  ? 48
                  : 20,
          height: 32,
          padding: const EdgeInsets.symmetric(horizontal: 12),
          color: themeData.colorScheme.secondary,
          disabledColor: themeData.splashColor,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(3),
          ),
          onPressed: isButtonEnabled ? onPressed : null,
          materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
          child: ScaleText(
            buildText(),
            style: TextStyle(
              color: themeData.textTheme.bodyLarge?.color,
              fontSize: 17,
              fontWeight: FontWeight.normal,
            ),
            overflow: TextOverflow.fade,
            softWrap: false,
            semanticsLabel: () {
              if (isWeChatMoment && hasVideo) {
                return semanticsTextDelegate.confirm;
              }
              if (provider!.isSelectedNotEmpty) {
                return '${semanticsTextDelegate.confirm}'
                    ' (${provider.currentlySelectedAssets.length}'
                    '/'
                    '${selectorProvider!.maxAssets})';
              }
              return semanticsTextDelegate.confirm;
            }(),
          ),
        );
      },
    ),
  );
}