From 398c7a4168f7d5eba5c2c631e2e6b7d6bda70d29 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 24 May 2026 17:07:09 +0200 Subject: [PATCH] Refactoring --- lib/core/common.dart | 2 +- .../create_match/choose_game_view.dart | 2 +- .../create_match/create_game_view.dart | 4 ++-- .../statistic_tile_factory.dart | 24 ++++++------------- lib/presentation/widgets/game_label.dart | 2 +- lib/presentation/widgets/tiles/game_tile.dart | 2 +- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/core/common.dart b/lib/core/common.dart index 31d039a..df88ea3 100644 --- a/lib/core/common.dart +++ b/lib/core/common.dart @@ -48,7 +48,7 @@ String translateAppColorToString(AppColor color, BuildContext context) { } /// Returns the [Color] object corresponding to a [AppColor] enum value. -Color getColorFromGameColor(AppColor color) { +Color getColorFromAppColor(AppColor color) { switch (color) { case AppColor.red: return Colors.red; diff --git a/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart b/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart index 3c51cab..4d085d7 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart @@ -164,7 +164,7 @@ class _ChooseGameViewState extends State { game.ruleset, context, ), - badgeColor: getColorFromGameColor(game.color), + badgeColor: getColorFromAppColor(game.color), isHighlighted: selectedGameId == game.id, onTap: () async { setState(() { diff --git a/lib/presentation/views/main_menu/match_view/create_match/create_game_view.dart b/lib/presentation/views/main_menu/match_view/create_match/create_game_view.dart index 06f15db..0671055 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/create_game_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/create_game_view.dart @@ -467,7 +467,7 @@ class _CreateGameViewState extends State { height: 16, margin: const EdgeInsets.only(left: 12), decoration: BoxDecoration( - color: getColorFromGameColor( + color: getColorFromAppColor( _colors[index].$1, ), shape: BoxShape.circle, @@ -501,7 +501,7 @@ class _CreateGameViewState extends State { width: 16, height: 16, decoration: BoxDecoration( - color: getColorFromGameColor(selectedColor!), + color: getColorFromAppColor(selectedColor!), shape: BoxShape.circle, ), ), diff --git a/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart b/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart index c482a7d..8461f6d 100644 --- a/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart +++ b/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart @@ -1,6 +1,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; +import 'package:tallee/core/common.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/models/match.dart'; import 'package:tallee/data/models/player.dart'; @@ -9,8 +10,11 @@ import 'package:tallee/presentation/views/main_menu/statistics_view/create_stati show translateStatisticTypeToString; import 'package:tallee/presentation/widgets/tiles/statistics_tile.dart'; -/// Build the [StatisticsTile] for a given [Statistic]. +List _colorPalette = AppColor.values + .map((c) => getColorFromAppColor(c)) + .toList(); +/// Build the [StatisticsTile] for a given [Statistic]. Widget buildStatisticTile({ required Statistic statistic, required List matches, @@ -272,24 +276,10 @@ IconData _getStatisticIcon({required StatisticType type}) { } } -/// The bar colors for the statistic tiles -const List _palette = [ - Color(0xFF4CAF50), // green - Color(0xFF2196F3), // blue - Color(0xFFFF9800), // orange - Color(0xFFE91E63), // pink - Color(0xFF9C27B0), // purple - Color(0xFF00BCD4), // cyan - Color(0xFFFFC107), // amber - Color(0xFF3F51B5), // indigo - Color(0xFF8BC34A), // light green - Color(0xFFFF5722), // deep orange -]; - /// Returns a color from the palette based on the statistic's ID as random seed. Color _getStatisticColor(Statistic stat) { final seed = stat.id.hashCode; - return _palette[seed.abs() % _palette.length]; + return _colorPalette[seed.abs() % _colorPalette.length]; } /* Skeleton data */ @@ -308,7 +298,7 @@ Widget buildSkeletonStatisticTile({required BuildContext context}) { width: MediaQuery.sizeOf(context).width * 0.95, values: values, itemCount: count, - barColor: _palette[Random().nextInt(_palette.length)], + barColor: _colorPalette[Random().nextInt(_colorPalette.length)], statistic: Statistic( type: StatisticType.totalMatches, scopes: [StatisticScope.allPlayers], diff --git a/lib/presentation/widgets/game_label.dart b/lib/presentation/widgets/game_label.dart index 3eae9b1..dd179d6 100644 --- a/lib/presentation/widgets/game_label.dart +++ b/lib/presentation/widgets/game_label.dart @@ -16,7 +16,7 @@ class GameLabel extends StatelessWidget { @override Widget build(BuildContext context) { - final backgroundColor = getColorFromGameColor(color); + final backgroundColor = getColorFromAppColor(color); final fontColor = backgroundColor.computeLuminance() > 0.5 ? Colors.black : Colors.white; diff --git a/lib/presentation/widgets/tiles/game_tile.dart b/lib/presentation/widgets/tiles/game_tile.dart index 11d96d8..4fb12d1 100644 --- a/lib/presentation/widgets/tiles/game_tile.dart +++ b/lib/presentation/widgets/tiles/game_tile.dart @@ -51,7 +51,7 @@ class GameTile extends StatelessWidget { ? (badgeColor!.computeLuminance() > 0.5 ? Colors.black : Colors.white) : Colors.white; - final gameColor = badgeColor ?? getColorFromGameColor(AppColor.orange); + final gameColor = badgeColor ?? getColorFromAppColor(AppColor.orange); return GestureDetector( onTap: () async {