withBorder method

AbstractButtonStyle withBorder({
  1. Border? border,
  2. Border? hoverBorder,
  3. Border? focusBorder,
  4. Border? disabledBorder,
})

Creates a copy with custom borders for different states.

Modifies the decoration to apply state-specific borders. Only works with BoxDecoration; other decoration types are returned unchanged.

Parameters:

  • border: Border for normal state
  • hoverBorder: Border when hovered
  • focusBorder: Border when focused
  • disabledBorder: Border when disabled

Example:

final style = ButtonVariance.outline.withBorder(
  border: Border.all(color: Colors.blue),
  hoverBorder: Border.all(color: Colors.blue.shade700, width: 2),
);

Implementation

AbstractButtonStyle withBorder(
    {Border? border,
    Border? hoverBorder,
    Border? focusBorder,
    Border? disabledBorder}) {
  return copyWith(
    decoration: (context, states, decoration) {
      if (decoration is BoxDecoration) {
        return decoration.copyWith(
          border: states.disabled
              ? disabledBorder ?? decoration.border
              : states.hovered
                  ? hoverBorder ?? decoration.border
                  : states.focused
                      ? focusBorder ?? decoration.border
                      : border,
        );
      }
      return decoration;
    },
  );
}