76 lines
2.1 KiB
Dart
76 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../constants/ui_constants.dart';
|
|
|
|
/// Custom button widget
|
|
class CustomButton extends StatelessWidget {
|
|
final String text;
|
|
final VoidCallback? onPressed;
|
|
final bool isLoading;
|
|
final bool isOutlined;
|
|
final IconData? icon;
|
|
final Color? backgroundColor;
|
|
|
|
const CustomButton({
|
|
super.key,
|
|
required this.text,
|
|
this.onPressed,
|
|
this.isLoading = false,
|
|
this.isOutlined = false,
|
|
this.icon,
|
|
this.backgroundColor,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (isOutlined) {
|
|
return OutlinedButton.icon(
|
|
onPressed: isLoading ? null : onPressed,
|
|
icon: isLoading
|
|
? const SizedBox(
|
|
width: UIConstants.iconSizeS,
|
|
height: UIConstants.iconSizeS,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: Icon(icon ?? Icons.check),
|
|
label: Text(text),
|
|
style: OutlinedButton.styleFrom(
|
|
minimumSize: const Size(double.infinity, UIConstants.buttonHeightM),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (icon != null) {
|
|
return ElevatedButton.icon(
|
|
onPressed: isLoading ? null : onPressed,
|
|
icon: isLoading
|
|
? const SizedBox(
|
|
width: UIConstants.iconSizeS,
|
|
height: UIConstants.iconSizeS,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: Icon(icon),
|
|
label: Text(text),
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size(double.infinity, UIConstants.buttonHeightM),
|
|
backgroundColor: backgroundColor,
|
|
),
|
|
);
|
|
}
|
|
|
|
return ElevatedButton(
|
|
onPressed: isLoading ? null : onPressed,
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size(double.infinity, UIConstants.buttonHeightM),
|
|
backgroundColor: backgroundColor,
|
|
),
|
|
child: isLoading
|
|
? const SizedBox(
|
|
width: UIConstants.iconSizeM,
|
|
height: UIConstants.iconSizeM,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: Text(text),
|
|
);
|
|
}
|
|
}
|