copyWith method

Creates a copy of this style with selectively replaced properties.

Each parameter is a ButtonStatePropertyDelegate that can modify or replace the corresponding style property. If all parameters are null, returns the original style unchanged for efficiency.

Example:

final customStyle = ButtonVariance.primary.copyWith(
  decoration: (context, states, defaultDecoration) {
    // Custom decoration logic
    return myCustomDecoration;
  },
);

Implementation

AbstractButtonStyle copyWith({
  ButtonStatePropertyDelegate<Decoration>? decoration,
  ButtonStatePropertyDelegate<MouseCursor>? mouseCursor,
  ButtonStatePropertyDelegate<EdgeInsetsGeometry>? padding,
  ButtonStatePropertyDelegate<TextStyle>? textStyle,
  ButtonStatePropertyDelegate<IconThemeData>? iconTheme,
  ButtonStatePropertyDelegate<EdgeInsetsGeometry>? margin,
}) {
  if (decoration == null &&
      mouseCursor == null &&
      padding == null &&
      textStyle == null &&
      iconTheme == null &&
      margin == null) {
    return this;
  }
  return _CopyWithButtonStyle(
    this,
    decoration,
    mouseCursor,
    padding,
    textStyle,
    iconTheme,
    margin,
  );
}