build method

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

Apply styles and build as TextButton

Equivalent to

TextButton()

Example usage:

build(context) {
  return (
    NikuButton(Text("Applied Style"))
      .px(40)
      .py(20)
      .bg(Colors.blue)
  )
}

Implementation

@override
Widget build(BuildContext context) {
  final composeTextStyle = ({
    Color? color,
  }) =>
      TextStyle(
        color: color,
        backgroundColor: _text_backgroundColor,
        fontSize: _text_fontSize,
        fontWeight: _text_fontWeight,
        fontStyle: _text_fontStyle,
        letterSpacing: _text_letterSpacing,
        wordSpacing: _text_wordSpacing,
        height: _text_height,
        foreground: _text_foreground,
        background: _text_background,
        shadows: _text_shadows,
        fontFeatures: _text_fontFeatures,
        decoration: _text_textDecoration,
        decorationColor: _text_textDecorationColor,
        decorationThickness: _text_textDecorationThickness,
        fontFamily: _text_fontFamily,
        fontFamilyFallback: _text_fontFamilyFallback,
        textBaseline: _text_textBaseline,
      );

  final buttonStyle = ButtonStyle(
    textStyle: MaterialStateProperty.resolveWith<TextStyle>((states) {
      if (states.contains(MaterialState.disabled))
        return composeTextStyle(color: _text_color._disabled);
      if (states.contains(MaterialState.dragged))
        return composeTextStyle(color: _text_color._dragged);
      if (states.contains(MaterialState.error))
        return composeTextStyle(color: _text_color._error);
      if (states.contains(MaterialState.focused))
        return composeTextStyle(color: _text_color._focused);
      if (states.contains(MaterialState.hovered))
        return composeTextStyle(color: _text_color._hovered);
      if (states.contains(MaterialState.pressed))
        return composeTextStyle(color: _text_color._pressed);
      if (states.contains(MaterialState.selected))
        return composeTextStyle(color: _text_color._selected);

      return composeTextStyle(color: _text_color._base);
    }),
    padding: MaterialStateProperty.resolveWith<EdgeInsetsGeometry>(
      (_) => EdgeInsets.only(
        top: _pt,
        left: _pl,
        bottom: _pb,
        right: _pr,
      ),
    ),
    backgroundColor: _composeMaterialState<Color>(_backgroundColor),
    foregroundColor: _composeMaterialState<Color>(_foregroundColor),
    overlayColor: _composeMaterialState<Color>(_overlayColor),
    shadowColor: _composeMaterialState<Color>(_shadowColor),
    elevation: _composeMaterialState<double>(_elevation),
    minimumSize: _composeMaterialState<Size>(getMinimumSize),
    side: _composeMaterialState<BorderSide>(_side),
    shape: _composeMaterialState<OutlinedBorder>(_shape),
    mouseCursor: _composeMaterialState<MouseCursor>(getMouseCursor),
    visualDensity: _visualDensity,
    tapTargetSize: _tapTargetSize,
    animationDuration: _animationDuration,
    enableFeedback: _enableFeedback,
    alignment: _alignment,
  );

  if (type == NikuButtonType.Elevated)
    return internalBuild(
      ElevatedButton(
        child: child,
        key: key,
        onPressed: _onPressed,
        onLongPress: _onLongPressed,
        focusNode: _focusNode,
        autofocus: _autofocus,
        clipBehavior: _clipBehavior,
        style: buttonStyle,
      ),
    );

  if (type == NikuButtonType.Outlined)
    return internalBuild(
      OutlinedButton(
        child: child,
        key: key,
        onPressed: _onPressed,
        onLongPress: _onLongPressed,
        focusNode: _focusNode,
        autofocus: _autofocus,
        clipBehavior: _clipBehavior,
        style: buttonStyle,
      ),
    );

  if (type == NikuButtonType.TextIcon)
    return internalBuild(
      TextButton.icon(
        icon: child,
        key: key,
        label: _label ?? Text("Icon Button"),
        onPressed: _onPressed,
        onLongPress: _onLongPressed,
        focusNode: _focusNode,
        autofocus: _autofocus,
        clipBehavior: _clipBehavior,
        style: buttonStyle,
      ),
    );

  if (type == NikuButtonType.ElevatedIcon)
    return internalBuild(
      ElevatedButton.icon(
        icon: child,
        key: key,
        label: _label ?? Text("Icon Button"),
        onPressed: _onPressed,
        onLongPress: _onLongPressed,
        focusNode: _focusNode,
        autofocus: _autofocus,
        clipBehavior: _clipBehavior,
        style: buttonStyle,
      ),
    );

  if (type == NikuButtonType.OutlinedIcon)
    return internalBuild(
      OutlinedButton.icon(
        icon: child,
        key: key,
        label: _label ?? Text("Icon Button"),
        onPressed: _onPressed,
        onLongPress: _onLongPressed,
        focusNode: _focusNode,
        autofocus: _autofocus,
        clipBehavior: _clipBehavior,
        style: buttonStyle,
      ),
    );

  return internalBuild(
    TextButton(
      child: child,
      key: key,
      onPressed: _onPressed,
      onLongPress: _onLongPressed,
      focusNode: _focusNode,
      autofocus: _autofocus,
      clipBehavior: _clipBehavior,
      style: buttonStyle,
    ),
  );
}