bharat_erp/lib/shared/widgets/app_button.dart
2026-07-17 14:35:10 +05:30

67 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
class AppButton extends StatelessWidget {
const AppButton({
super.key,
required this.label,
required this.onPressed,
this.isLoading = false,
this.isOutlined = false,
this.icon,
this.expand = true,
});
final String label;
final VoidCallback? onPressed;
final bool isLoading;
final bool isOutlined;
final IconData? icon;
final bool expand;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final primary = theme.colorScheme.primary;
final onPrimary = theme.colorScheme.onPrimary;
final secondary = theme.colorScheme.secondary;
final child = isLoading
? SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: isOutlined ? secondary : onPrimary,
),
)
: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (icon != null) ...[Icon(icon, size: 20), const SizedBox(width: 8)],
Text(label),
],
);
final button = isOutlined
? OutlinedButton(
onPressed: isLoading ? null : onPressed,
style: OutlinedButton.styleFrom(
foregroundColor: secondary,
side: BorderSide(color: secondary.withValues(alpha: 0.55)),
),
child: child,
)
: ElevatedButton(
onPressed: isLoading ? null : onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: primary,
foregroundColor: onPrimary,
),
child: child,
);
return expand ? SizedBox(width: double.infinity, child: button) : button;
}
}