text static method

Widget text({
  1. Key? key,
  2. required Widget child,
  3. double? width,
  4. double? height,
  5. ZeroSizeType buttonSizeType = ZeroSizeType.medium,
  6. ZeroButtonRadiusType buttonRadiusType = ZeroButtonRadiusType.rectangle,
  7. bool isDisabled = false,
  8. required VoidCallback onPressed,
  9. VoidCallback? onLongPress,
  10. ZeroButtonStyle? style,
  11. FocusNode? focusNode,
  12. bool autofocus = false,
})

Implementation

static Widget text({
  Key? key,

  /// [child] is the widget that will be displayed on the button
  required Widget child,

  /// [width] is the width for [ZeroButton]
  /// if this value is null, widget will be sized to fit its contents
  double? width,

  /// [height] is the height for [ZeroButton]
  /// if this value is null, the default height get from [defaultButtonHeight] which is the value based on [buttonSizeType]
  double? height,
  ZeroSizeType buttonSizeType = ZeroSizeType.medium,

  /// [buttonRadiusType] is the type of radius for [ZeroButton]
  /// [ZeroButtonRadiusType.rectangle] is the type of radius for [ZeroButton] that has rectangle shape
  /// [ZeroButtonRadiusType.rounded] is the type of radius for [ZeroButton] that has rounded shape
  /// [ZeroButtonRadiusType.curved] is the type of radius for [ZeroButton] that has curved shape
  ZeroButtonRadiusType buttonRadiusType = ZeroButtonRadiusType.rectangle,

  /// [isDisabled] is the flag to determine if the button is disabled or not
  bool isDisabled = false,
  required VoidCallback onPressed,
  VoidCallback? onLongPress,

  /// [ZeroButtonStyle] is the style for [ZeroButton]
  /// if this value is null, the default style will be used
  /// which is defined in [secondaryDefaultStyle]
  ///
  /// [style] used for customizing [ZeroButton]
  ZeroButtonStyle? style,
  FocusNode? focusNode,
  bool autofocus = false,
}) {
  return Builder(builder: (context) {
    final theme = context.theme;
    final buttonStyle = theme.textButtonStyle;

    /// [textDefaultStyle] is the default style for [ZeroButton.text]
    final ZeroButtonStyle textDefaultStyle = buttonStyle.merge(
      ZeroButtonStyle(
        textStyle: buttonStyle.textStyle
            ?.copyWith(fontSize: buttonSizeType.fontSize),
        foregroundColor: buttonStyle.foregroundColor ?? ZeroColors.neutral,
        animatingColor:
            buttonStyle.animatingColor ?? theme.primaryColor.lighter,
        elevation: 0,
        fixedSize: (width != null)
            ? Size(width, height ?? buttonSizeType.defaultButtonHeight)
            : null,
        padding: buttonSizeType.padding,
        shape: RoundedRectangleBorder(
          borderRadius: buttonRadiusSize(buttonRadiusType),
        ),
      ),
    );

    /// if [style] is not null, merge [style] with [textDefaultStyle]
    /// combine customizations from [style] with default style [textDefaultStyle]
    final adaptiveStyle = textDefaultStyle.merge(style);
    final textStyle =
        (theme.typography.button ?? DefaultTextStyle.of(context).style)
            .copyWith(fontSize: buttonSizeType.fontSize)
            .merge(adaptiveStyle.textStyle)
            .copyWith(color: adaptiveStyle.foregroundColor);

    return isDisabled
        ? disabled(
            child: child,
            width: width,
            height: height,
            buttonSizeType: buttonSizeType,
            buttonRadiusType: buttonRadiusType,
            style: adaptiveStyle,
          )
        : ZeroButton._(
            key: key,
            onPressed: onPressed,
            onLongPress: onLongPress,
            style: adaptiveStyle,
            focusNode: focusNode,
            autofocus: autofocus,
            child: IconTheme(
              data: IconTheme.of(context)
                  .copyWith(color: adaptiveStyle.foregroundColor),
              child: DefaultTextStyle(
                style: textStyle,
                child: child,
              ),
            ),
          );
  });
}