buildStyledButton function

ElevatedButton buildStyledButton({
  1. required BuildContext context,
  2. required String label,
  3. required VoidCallback onPressed,
  4. Color? backgroundColor,
  5. Color? foregroundColor,
  6. 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),
  );
}