BZButton constructor
BZButton({
- Key? key,
- required String text,
- bool enabled = true,
- VoidCallback? onPressed,
- Color? enabledColor,
- Color? disabledColor,
- Color? enabledTextColor,
- Color? disabledTextColor,
- ButtonStyle style = const ButtonStyle(),
Implementation
BZButton({
Key? key,
required String text,
this.enabled = true,
this.onPressed,
this.enabledColor,
this.disabledColor,
this.enabledTextColor,
this.disabledTextColor,
ButtonStyle style = const ButtonStyle(),
}) : super(
key: key,
onPressed: enabled ? onPressed : null,
style: style.copyWith(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.disabled)) {
return disabledColor ?? Colors.grey;
}
return enabledColor ?? Colors.purple;
},
),
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.disabled)) {
return disabledTextColor ?? Colors.white54;
}
return enabledTextColor ?? Colors.white;
},
),
),
child: Text(
text,
style: TextStyle(
color: enabled
? (enabledTextColor ?? Colors.white)
: (disabledTextColor ?? Colors.white54),
fontSize: 16,
),
),
);