withBackgroundColor method
Creates a copy with custom background colors for different states.
Modifies the decoration to apply state-specific background colors. Only works with BoxDecoration; other decoration types are returned unchanged.
Parameters:
color: Background color for normal statehoverColor: Background color when hoveredfocusColor: Background color when focuseddisabledColor: Background color when disabled
Example:
final style = ButtonVariance.primary.withBackgroundColor(
color: Colors.blue,
hoverColor: Colors.blue.shade700,
);
Implementation
AbstractButtonStyle withBackgroundColor({
Color? color,
Color? hoverColor,
Color? focusColor,
Color? disabledColor,
}) {
return copyWith(
decoration: (context, states, decoration) {
if (decoration is BoxDecoration) {
return decoration.copyWith(
color: states.disabled
? disabledColor ?? decoration.color
: states.hovered
? hoverColor ?? decoration.color
: states.focused
? focusColor ?? decoration.color
: color,
);
}
return decoration;
},
);
}