schleifchenturnier_25/lib/features/tournament/presentation/screens/fields_screen.dart
2025-12-11 08:20:15 +01:00

162 lines
6.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// lib/features/tournament/presentation/screens/fields_screen.dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter/services.dart';
import '../../data/models/player_model.dart';
import '../provider/player_provider.dart';
import '../provider/shuffle_provider.dart'; // <-- jetzt mit shuffleResultProvider + shuffleControllerProvider
import '../widgets/volleyball_field_widget.dart';
class FieldsScreen extends ConsumerWidget {
const FieldsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
// Hier lesen wir den aktuellen Shuffle-Stand aus
final shuffleResult = ref.watch(shuffleResultProvider);
final fields = shuffleResult.fields;
final bench = shuffleResult.bench;
final message = shuffleResult.message;
return Scaffold(
body: Column(
children: [
// Swipe-Galerie
Expanded(
child: PageView.builder(
itemCount: 3,
itemBuilder: (context, index) {
final fieldPlayers = index < fields.length ? fields[index] : <PlayerModel>[];
final teamA = fieldPlayers.isNotEmpty
? fieldPlayers.sublist(0, fieldPlayers.length.clamp(0, 6))
: <PlayerModel>[];
final teamB = fieldPlayers.length > 6
? fieldPlayers.sublist(6, fieldPlayers.length.clamp(6, 12))
: <PlayerModel>[];
return Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Expanded(
child: VolleyballFieldWidget(
teamA: teamA,
teamB: teamB,
fieldNumber: index + 1,
),
),
const SizedBox(height: 20),
Row(
children: [
Expanded(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green.shade600,
padding: const EdgeInsets.symmetric(vertical: 20),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
bottomLeft: Radius.circular(20),
),
),
),
onPressed: teamA.isEmpty
? null
: () async {
await HapticFeedback.mediumImpact();
ref.read(playerListProvider.notifier).awardWinToPlayers(teamA);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Oben gewinnt! +1 Schleifchen für ${teamA.length} Spieler'),
backgroundColor: Colors.green,
duration: const Duration(milliseconds: 800),
),
);
},
child: const Text('OBEN GEWINNT', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
),
),
Expanded(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red.shade600,
padding: const EdgeInsets.symmetric(vertical: 20),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20),
),
),
),
onPressed: teamB.isEmpty
? null
: () async {
await HapticFeedback.mediumImpact();
ref.read(playerListProvider.notifier).awardWinToPlayers(teamB);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Unten gewinnt! +1 Schleifchen für ${teamB.length} Spieler'),
backgroundColor: Colors.red,
duration: const Duration(milliseconds: 800),
),
);
},
child: const Text('UNTEN GEWINNT', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
),
),
],
),
],
),
);
},
),
),
// Aussetzer
if (bench.isNotEmpty)
Container(
padding: const EdgeInsets.all(16),
color: Colors.orange.shade100,
child: Column(
children: [
const Text('Aussetzer diese Runde:', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
const SizedBox(height: 8),
Wrap(
spacing: 12,
runSpacing: 8,
children: bench
.map((p) => Chip(label: Text(p.name), backgroundColor: Colors.orange.shade300))
.toList(),
),
],
),
),
// NEUER SHUFFLE-BUTTON ruft den Controller auf
Padding(
padding: const EdgeInsets.all(16),
child: ElevatedButton.icon(
icon: const Icon(Icons.shuffle),
label: Text(
message.isEmpty ? 'Neu mischen' : message,
style: const TextStyle(fontSize: 18),
),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.deepPurple,
),
onPressed: () async {
await HapticFeedback.selectionClick();
// Das ist der entscheidende Aufruf!
ref.read(shuffleControllerProvider).shuffle();
},
),
),
],
),
);
}
}