Files
Finlytic/FinlyticApp/lib/features/trades/widgets/trade_performance_bar.dart
T

56 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../core/theme/app_theme.dart';
import '../../../../core/widgets/glass_container.dart';
import '../models/trade_model.dart';
class TradePerformanceBar extends StatelessWidget {
final List<TradeModel> activeTrades;
final List<TradeModel> allTrades;
final List<TradeModel> proposals;
const TradePerformanceBar({
super.key,
required this.activeTrades,
required this.allTrades,
required this.proposals,
});
Widget _summaryStat(String label, String value, Color color) {
return Column(
children: [
Text(label, style: TextStyle(color: AppTheme.textMuted, fontSize: 11)),
const SizedBox(height: 4),
Text(value, style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 15)),
],
);
}
@override
Widget build(BuildContext context) {
final totalOpenPnlAbs = activeTrades.fold<double>(0, (sum, t) => sum + t.pnlEur);
final isPnlPos = totalOpenPnlAbs >= 0;
final closedTrades = allTrades.where((t) => t.isClosed).toList();
final winRatePct = closedTrades.isNotEmpty
? (closedTrades.where((t) => t.pnlEur >= 0).length / closedTrades.length * 100)
: 0.0;
return GlassContainer(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
margin: const EdgeInsets.only(bottom: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_summaryStat('Offene Trades', '${activeTrades.length}', AppTheme.primaryEmerald),
_summaryStat(
'Offenes PnL',
'${isPnlPos ? '+' : ''}${totalOpenPnlAbs.toStringAsFixed(2)}',
isPnlPos ? AppTheme.primaryEmerald : AppTheme.accentRed,
),
_summaryStat('Trefferquote', '${winRatePct.toStringAsFixed(0)}%', Colors.amber),
_summaryStat('Auto-Vorschläge', '${proposals.length}', AppTheme.accentCyan),
],
),
);
}
}