Files
Finlytic/FinlyticApp/lib/features/bot/widgets/bot_settings_sheet.dart
T

170 lines
6.1 KiB
Dart

import 'package:flutter/material.dart';
import '../../../core/theme/app_theme.dart';
import '../models/bot_models.dart';
class BotSettingsSheet extends StatefulWidget {
final BotStatusModel currentStatus;
final Function(bool autoExec, int maxPos, double risk, int minScore) onSave;
final VoidCallback onPanicClose;
const BotSettingsSheet({
super.key,
required this.currentStatus,
required this.onSave,
required this.onPanicClose,
});
@override
State<BotSettingsSheet> createState() => _BotSettingsSheetState();
}
class _BotSettingsSheetState extends State<BotSettingsSheet> {
late bool _autoExec;
late int _maxPositions;
late double _riskPerTrade;
late int _minScore;
@override
void initState() {
super.initState();
_autoExec = widget.currentStatus.autoExecutionEnabled;
_maxPositions = widget.currentStatus.maxPositions;
_riskPerTrade = widget.currentStatus.riskPerTradePercent;
_minScore = widget.currentStatus.minCompositeScore;
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: AppTheme.cardSurface,
borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Bot Konfiguration & Kill-Switch',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white),
),
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.close, color: Colors.white70),
),
],
),
const SizedBox(height: 16),
SwitchListTile(
title: const Text('Automatische Ausführung (Auto-Trade)', style: TextStyle(color: Colors.white)),
subtitle: Text('Führt geprüfte Signale ab Score ≥ $_minScore automatisch aus', style: TextStyle(color: AppTheme.textMuted, fontSize: 12)),
value: _autoExec,
activeThumbColor: AppTheme.primaryEmerald,
onChanged: (val) => setState(() => _autoExec = val),
),
const SizedBox(height: 12),
Text('Max. Parallele Positionen: $_maxPositions', style: const TextStyle(color: Colors.white70)),
Slider(
value: _maxPositions.toDouble(),
min: 1,
max: 10,
divisions: 9,
activeColor: AppTheme.primaryEmerald,
label: '$_maxPositions',
onChanged: (val) => setState(() => _maxPositions = val.toInt()),
),
const SizedBox(height: 8),
Text('Risiko pro Trade: ${_riskPerTrade.toStringAsFixed(1)}% des Portfolios', style: const TextStyle(color: Colors.white70)),
Slider(
value: _riskPerTrade,
min: 0.2,
max: 3.0,
divisions: 28,
activeColor: AppTheme.primaryEmerald,
label: '${_riskPerTrade.toStringAsFixed(1)}%',
onChanged: (val) => setState(() => _riskPerTrade = val),
),
const SizedBox(height: 8),
Text('Mindest-Score für Einstieg: $_minScore Punkte', style: const TextStyle(color: Colors.white70)),
Slider(
value: _minScore.toDouble(),
min: 60,
max: 95,
divisions: 35,
activeColor: AppTheme.primaryEmerald,
label: '$_minScore Pkt',
onChanged: (val) => setState(() => _minScore = val.toInt()),
),
const SizedBox(height: 20),
Row(
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () {
widget.onSave(_autoExec, _maxPositions, _riskPerTrade, _minScore);
Navigator.of(context).pop();
},
icon: const Icon(Icons.check),
label: const Text('Speichern'),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.primaryEmerald,
padding: const EdgeInsets.symmetric(vertical: 14),
),
),
),
const SizedBox(width: 12),
ElevatedButton.icon(
onPressed: () {
Navigator.of(context).pop();
_showPanicConfirmation(context);
},
icon: const Icon(Icons.warning, color: Colors.white),
label: const Text('PANIC CLOSE', style: TextStyle(color: Colors.white)),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentRed,
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 16),
),
),
],
),
const SizedBox(height: 16),
],
),
);
}
void _showPanicConfirmation(BuildContext context) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: AppTheme.cardSurface,
title: Text('🚨 Notverkauf bestätigen', style: TextStyle(color: AppTheme.accentRed)),
content: const Text(
'Möchtest du wirklich SOFORT alle offenen Bot-Positionen schließen? Dieser Vorgang kann nicht rückgängig gemacht werden.',
style: TextStyle(color: Colors.white70),
),
actions: [
TextButton(
onPressed: () => Navigator.of(ctx).pop(),
child: const Text('Abbrechen', style: TextStyle(color: Colors.white70)),
),
ElevatedButton(
onPressed: () {
Navigator.of(ctx).pop();
widget.onPanicClose();
},
style: ElevatedButton.styleFrom(backgroundColor: AppTheme.accentRed),
child: const Text('ALLE POSITIONEN SCHLIESSEN'),
),
],
),
);
}
}