69 lines
1.8 KiB
Dart
69 lines
1.8 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}) {
|
|
final sUpper = status.trim().toUpperCase();
|
|
Color bg;
|
|
if (sUpper.contains('POS')) {
|
|
bg = AppTheme.primaryEmerald;
|
|
} else if (sUpper.contains('NEG')) {
|
|
bg = AppTheme.accentRed;
|
|
} else if (sUpper.contains('NEU')) {
|
|
bg = AppTheme.accentCyan;
|
|
} else if (score != null) {
|
|
if (score > 0.15) {
|
|
bg = AppTheme.primaryEmerald;
|
|
} else if (score < -0.15) {
|
|
bg = AppTheme.accentRed;
|
|
} else {
|
|
bg = AppTheme.accentCyan;
|
|
}
|
|
} else {
|
|
bg = AppTheme.textMuted;
|
|
}
|
|
return StatusBadge(label: sUpper.isNotEmpty ? sUpper : 'NEUTRAL', 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,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|