summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Frank <conjfrnk@gmail.com>2024-04-01 19:04:41 -0400
committerConnor Frank <conjfrnk@gmail.com>2024-04-01 19:04:41 -0400
commit0c1ae39433e4f2f170b6a02065db209211cd03b5 (patch)
tree71fa1f68134803194ab61e9016af5d8bd6f18c56
parent4c5ba92b066560e9de76ac14a491d789453617d8 (diff)
Tapping Total Par Shows Ranking
-rw-r--r--lib/scorekeeper.dart61
1 files changed, 56 insertions, 5 deletions
diff --git a/lib/scorekeeper.dart b/lib/scorekeeper.dart
index 57cd1ed..0c67f6e 100644
--- a/lib/scorekeeper.dart
+++ b/lib/scorekeeper.dart
@@ -326,6 +326,52 @@ class _ScoreKeeperState extends State<ScoreKeeper> {
);
}
+ void _showPlayerRankings(BuildContext context) {
+ // Calculate total scores for each player
+ Map<String, int> totalScores = {};
+ for (var name in playerNames) {
+ int totalScore = 0;
+ scores.forEach((hole, playerScores) {
+ int playerIndex = playerNames.indexOf(name);
+ if (playerScores.length > playerIndex) {
+ totalScore += playerScores[playerIndex];
+ }
+ });
+ totalScores[name] = totalScore;
+ }
+
+ // Remove players with a total score of 0
+ totalScores.removeWhere((name, score) => score == 0);
+
+ // Sort players by total score
+ var sortedScores = totalScores.entries.toList()
+ ..sort((a, b) => a.value.compareTo(b.value));
+
+ // Create a list of player names and scores for display, sorted by score
+ List<Widget> scoreWidgets = sortedScores.map((entry) {
+ return Text('${entry.key}: ${entry.value}');
+ }).toList();
+
+ // Show the rankings in a dialog
+ showDialog(
+ context: context,
+ builder: (BuildContext context) {
+ return AlertDialog(
+ title: const Text('Player Rankings'),
+ content: SingleChildScrollView(
+ child: ListBody(children: scoreWidgets),
+ ),
+ actions: <Widget>[
+ TextButton(
+ child: const Text('OK'),
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ ],
+ );
+ },
+ );
+ }
+
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -395,13 +441,18 @@ class _ScoreKeeperState extends State<ScoreKeeper> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Total Par Display
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 8.0),
- child: Text(
- 'Total Par: ${pars.values.fold(0, (prev, par) => prev + par)}',
- style: const TextStyle(fontWeight: FontWeight.bold),
+ GestureDetector(
+ onTap: () => _showPlayerRankings(context),
+ child: Container(
+ padding: const EdgeInsets.all(10),
+ color: Colors.blueGrey[100],
+ child: Text(
+ 'Total Par: ${pars.values.fold(0, (prev, par) => prev + par)}',
+ style: const TextStyle(fontSize: 16),
+ ),
),
),
+
// Divider between Total Par and Players' Scores
const VerticalDivider(color: Colors.black),
// Players' Scores