buildWidget method

  1. @override
Widget buildWidget(
  1. BuildContext context, {
  2. T? param,
  3. Axis orientation = Axis.horizontal,
  4. bool compact = false,
  5. bool floating = false,
  6. String? tooltip,
})
override

Implementation

@override
Widget buildWidget(
  BuildContext context, {
  T? param,
  Axis orientation = Axis.horizontal,
  bool compact = false,
  bool floating = false,
  String? tooltip,
}) {
  final theme = Theme.of(context);

  final text = super.text(param ?? toolValue?.value) ?? '';
  final iconData = super.iconData(param);
  final enabled = super.enabled(param);
  final options = this.options(param);

  final textStyle = this.textStyle ??
      TextStyle(
        color: fontColor ?? theme.colorScheme.onSurface,
        fontSize: fontSize,
        shadows: textShadow
            ? [
                Shadow(
                  offset: const Offset(1, 1),
                  color: theme.colorScheme.shadow.withValues(alpha: 0.8),
                  blurRadius: 2,
                ),
                Shadow(
                  offset: const Offset(-1, -1),
                  color: Colors.white.withValues(alpha: 0.8),
                  blurRadius: 2,
                )
              ]
            : null,
      );

  final buttonStyle = TextButton.styleFrom(
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.zero,
    ),
  );

  Widget label = Text(
    text,
    style: textStyle,
  );

  final icon = super.icon(param) ??
      (iconData != null
          ? Icon(
              iconData,
              size: iconSize,
              color: iconColor ??
                  textStyle.color ??
                  fontColor ??
                  theme.colorScheme.onSurface,
            )
          : null);

  final isButton = super.onPressed != null;
  final isButtonEnabled = isButton && enabled;
  final onPressed = isButtonEnabled //
      ? () => super.onPressed!(param)
      : null;

  return Semantics(
    label: buttonSemanticsLabel ?? tooltip,
    blockUserActions: true,
    button: isButton,
    enabled: isButtonEnabled,
    child: (options != null &&
            options.isNotEmpty &&
            onOption != null &&
            (options.length > 1 || options.first != text))
        ? _TextOptionsButton(
            label: label,
            options: options,
            onOption: onOption!,
            textStyle: textStyle,
            buttonStyle: buttonStyle,
            height: _height,
            icon: icon,
            iconSize: iconSize,
            paddingAdded: addPaddingForOptionsDropdown,
            alignDropdownToText: alignDropdownToText,
            animateDown: animateDown,
            optionsSemanticsLabel: optionsSemanticsLabel,
            onPressed: onPressed,
            onInit: onInit,
            onDispose: onDispose,
          )
        : _TextButton(
            label: label,
            buttonStyle: buttonStyle,
            icon: icon,
            onPressed: onPressed,
            height: _height,
            onInit: onInit,
            onDispose: onDispose,
          ),
  );
}