buildStyledButton function
ElevatedButton
buildStyledButton({
- required BuildContext context,
- required String label,
- required VoidCallback onPressed,
- Color? backgroundColor,
- Color? foregroundColor,
- TextStyle? textStyle,
A reusable function that builds a styled ElevatedButton.
Implementation
ElevatedButton buildStyledButton({
required BuildContext context,
required String label,
required VoidCallback onPressed,
Color? backgroundColor,
Color? foregroundColor,
TextStyle? textStyle,
}) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
backgroundColor: backgroundColor ?? Colors.red,
foregroundColor: foregroundColor ?? Colors.white,
// You can pass a textStyle here:
textStyle:
textStyle ??
const TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),
),
onPressed: onPressed,
child: Text(label),
);
}