99 lines
2.6 KiB
Dart
99 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../utils/app_colors.dart';
|
|
|
|
class CustomButton extends StatelessWidget {
|
|
final String text;
|
|
final VoidCallback? onPressed;
|
|
final bool isLoading;
|
|
final bool isOutlined;
|
|
final IconData? icon;
|
|
final double? width;
|
|
final double height;
|
|
final Color? backgroundColor;
|
|
|
|
const CustomButton({
|
|
Key? key,
|
|
required this.text,
|
|
this.onPressed,
|
|
this.isLoading = false,
|
|
this.isOutlined = false,
|
|
this.icon,
|
|
this.width,
|
|
this.height = 56,
|
|
this.backgroundColor,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: width,
|
|
height: height,
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
child:
|
|
isOutlined
|
|
? OutlinedButton(
|
|
onPressed: isLoading ? null : onPressed,
|
|
style: OutlinedButton.styleFrom(
|
|
side: const BorderSide(color: AppColors.primaryRed, width: 2),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
child: _buildButtonContent(),
|
|
)
|
|
: ElevatedButton(
|
|
onPressed: isLoading ? null : onPressed,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: backgroundColor ?? AppColors.primaryRed,
|
|
foregroundColor: AppColors.textLight,
|
|
elevation: 2,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
child: _buildButtonContent(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildButtonContent() {
|
|
if (isLoading) {
|
|
return const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
valueColor: AlwaysStoppedAnimation<Color>(AppColors.textLight),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (icon != null) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(icon, size: 20),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
text,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: isOutlined ? AppColors.primaryRed : AppColors.textLight,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
return Text(
|
|
text,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: isOutlined ? AppColors.primaryRed : AppColors.textLight,
|
|
),
|
|
);
|
|
}
|
|
}
|