Files
Finlytic/FinlyticApp/lib/core/widgets/status_badge.dart
T

58 lines
1.6 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/app_theme.dart';
/// Reusable pill status badge widget for sentiment, trades, or user roles.
class StatusBadge extends StatelessWidget {
final String label;
final Color color;
final IconData? icon;
const StatusBadge({
super.key,
required this.label,
required this.color,
this.icon,
});
factory StatusBadge.sentiment(String status, {double? score}) {
Color bg = AppTheme.textMuted;
if (status.toUpperCase().contains('POS') || (score != null && score > 0.15)) {
bg = AppTheme.primaryEmerald;
} else if (status.toUpperCase().contains('NEG') || (score != null && score < -0.15)) {
bg = AppTheme.accentRed;
} else if (status.toUpperCase().contains('NEU')) {
bg = AppTheme.accentCyan;
}
return StatusBadge(label: status.toUpperCase(), color: bg);
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(6),
border: Border.all(color: color.withValues(alpha: 0.4), width: 1),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (icon != null) ...[
Icon(icon, size: 12, color: color),
const SizedBox(width: 4),
],
Text(
label,
style: TextStyle(
color: color,
fontWeight: FontWeight.bold,
fontSize: 11,
),
),
],
),
);
}
}