45 lines
1.2 KiB
Dart
45 lines
1.2 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 child = isLoading
|
|
? const SizedBox(
|
|
height: 20,
|
|
width: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: 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, child: child)
|
|
: ElevatedButton(onPressed: isLoading ? null : onPressed, child: child);
|
|
|
|
return expand ? SizedBox(width: double.infinity, child: button) : button;
|
|
}
|
|
}
|