Files
chat/client/flutter/lib/widgets/custom_button.dart
2026-04-25 16:36:34 +08:00

66 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:sales_chat/theme/app_theme.dart';
class CustomButton extends StatelessWidget {
final String text;
final VoidCallback? onPressed;
final bool isLoading;
final bool isOutlined;
final IconData? icon;
final Color? color;
const CustomButton({
super.key,
required this.text,
this.onPressed,
this.isLoading = false,
this.isOutlined = false,
this.icon,
this.color,
});
@override
Widget build(BuildContext context) {
final buttonColor = color ?? AppTheme.primaryColor;
if (isOutlined) {
return OutlinedButton.icon(
onPressed: isLoading ? null : onPressed,
icon: isLoading
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: (icon != null ? Icon(icon, size: 18) : const SizedBox.shrink()),
label: Text(text),
style: OutlinedButton.styleFrom(
foregroundColor: buttonColor,
side: BorderSide(color: buttonColor),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
);
}
return ElevatedButton.icon(
onPressed: isLoading ? null : onPressed,
icon: isLoading
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: (icon != null ? Icon(icon, size: 18) : const SizedBox.shrink()),
label: Text(text),
style: ElevatedButton.styleFrom(
backgroundColor: buttonColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
);
}
}