syncra_addons/creche_app/lib/shared/widgets/custom_button.dart

54 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
class CustomButton extends StatelessWidget {
final String text;
final VoidCallback? onPressed;
final Color? backgroundColor;
final Color? textColor;
final IconData? icon;
final bool isLoading;
const CustomButton({
super.key,
required this.text,
this.onPressed,
this.backgroundColor,
this.textColor,
this.icon,
this.isLoading = false,
});
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: isLoading ? null : onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: backgroundColor ?? Theme.of(context).colorScheme.primary,
foregroundColor: textColor ?? Colors.white,
minimumSize: const Size(double.infinity, 52),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
elevation: 2,
),
child: isLoading
? const SizedBox(
height: 22,
width: 22,
child: CircularProgressIndicator(
color: Colors.white, strokeWidth: 2.5),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (icon != null) ...[
Icon(icon, size: 20),
const SizedBox(width: 8),
],
Text(text,
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.bold)),
],
),
);
}
}