Implementation
@override
ButtonStyle get style {
Color? getColor(Set<MaterialState> states) {
Color color= backgroundPalette.normal;
if (states.contains(MaterialState.pressed)) {
color = backgroundPalette.pressed;
} else {
const Set<MaterialState> interactiveStates = <MaterialState>{
MaterialState.hovered,
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
color = backgroundPalette.hover;
}
}
color = disable ? color.withOpacity(_kDisableOpacity) : color;
return color;
}
Color? getForegroundColorColor(Set<MaterialState> states) {
Color color= foregroundPalette.normal;
if (states.contains(MaterialState.pressed)) {
color = foregroundPalette.pressed;
} else {
const Set<MaterialState> interactiveStates = <MaterialState>{
MaterialState.hovered,
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
color = foregroundPalette.hover;
}
}
color = disable ? color.withOpacity(_kDisableOpacity) : color;
return color;
}
Color? getBackgroundColor(Set<MaterialState> states) {
Color color = backgroundPalette.normal;
color = disable ? color.withOpacity(_kDisableOpacity) : color;
return color;
}
return ButtonStyle(
elevation: MaterialStatePropertyAll(elevation),
overlayColor: MaterialStateProperty.resolveWith(getColor),
foregroundColor: MaterialStateProperty.resolveWith(getForegroundColorColor),
backgroundColor: MaterialStateProperty.resolveWith(getBackgroundColor),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(borderRadius: borderRadius)),
padding: MaterialStateProperty.all(padding),
);
}