98 lines
3.5 KiB
Dart
98 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../provider/player_provider.dart';
|
|
import '../../data/models/player_model.dart';
|
|
|
|
class StatsScreen extends ConsumerWidget {
|
|
const StatsScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final allPlayers = ref.watch(playerListProvider);
|
|
|
|
// Sortiere absteigend nach Wins
|
|
final sortedPlayers = List<PlayerModel>.from(allPlayers)
|
|
..sort((a, b) => b.wins.compareTo(a.wins));
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Schleifchen-Rangliste'),
|
|
centerTitle: true,
|
|
),
|
|
body: sortedPlayers.isEmpty
|
|
? const Center(
|
|
child: Text(
|
|
'Noch keine Siege verteilt!\nSpielt eine Runde und lasst die Schleifchen fliegen! 🏐🎀',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 20, color: Colors.grey),
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: sortedPlayers.length,
|
|
itemBuilder: (context, index) {
|
|
final player = sortedPlayers[index];
|
|
final rank = index + 1;
|
|
|
|
// Podium-Farben
|
|
Color? backgroundColor;
|
|
Color? medalColor;
|
|
IconData? medalIcon;
|
|
|
|
if (index == 0 && player.wins > 0) {
|
|
backgroundColor = Colors.amber.shade100; // Gold
|
|
medalColor = Colors.amber.shade600;
|
|
medalIcon = Icons.looks_one;
|
|
} else if (index == 1 && player.wins > 0 && (sortedPlayers.length < 2 || player.wins < sortedPlayers[0].wins)) {
|
|
backgroundColor = Colors.grey.shade300; // Silber
|
|
medalColor = Colors.grey;
|
|
medalIcon = Icons.looks_two;
|
|
} else if (index == 2 && player.wins > 0 && (sortedPlayers.length < 3 || player.wins < sortedPlayers[1].wins)) {
|
|
backgroundColor = Colors.brown.shade200; // Bronze
|
|
medalColor = Colors.brown.shade700;
|
|
medalIcon = Icons.looks_3;
|
|
}
|
|
|
|
return Card(
|
|
color: backgroundColor,
|
|
elevation: backgroundColor != null ? 8 : 2,
|
|
margin: const EdgeInsets.symmetric(vertical: 6),
|
|
child: ListTile(
|
|
leading: medalIcon != null
|
|
? CircleAvatar(
|
|
backgroundColor: medalColor,
|
|
child: Icon(medalIcon, color: Colors.white, size: 28),
|
|
)
|
|
: CircleAvatar(
|
|
child: Text(
|
|
'$rank',
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
title: Text(
|
|
player.name,
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
|
),
|
|
subtitle: Text(
|
|
'${player.wins} Siege${player.wins == 1 ? '' : 'n'}',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
color: player.wins > 0 ? Colors.green.shade700 : Colors.grey,
|
|
),
|
|
),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: List.generate(player.wins.clamp(0, 5), (_) {
|
|
return const Padding(
|
|
padding: EdgeInsets.only(left: 4),
|
|
child: Icon(Icons.auto_awesome, color: Colors.amber, size: 20),
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
} |