Refactoring
This commit is contained in:
@@ -48,7 +48,7 @@ String translateAppColorToString(AppColor color, BuildContext context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [Color] object corresponding to a [AppColor] enum value.
|
/// Returns the [Color] object corresponding to a [AppColor] enum value.
|
||||||
Color getColorFromGameColor(AppColor color) {
|
Color getColorFromAppColor(AppColor color) {
|
||||||
switch (color) {
|
switch (color) {
|
||||||
case AppColor.red:
|
case AppColor.red:
|
||||||
return Colors.red;
|
return Colors.red;
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
|||||||
game.ruleset,
|
game.ruleset,
|
||||||
context,
|
context,
|
||||||
),
|
),
|
||||||
badgeColor: getColorFromGameColor(game.color),
|
badgeColor: getColorFromAppColor(game.color),
|
||||||
isHighlighted: selectedGameId == game.id,
|
isHighlighted: selectedGameId == game.id,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
@@ -467,7 +467,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
height: 16,
|
height: 16,
|
||||||
margin: const EdgeInsets.only(left: 12),
|
margin: const EdgeInsets.only(left: 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: getColorFromGameColor(
|
color: getColorFromAppColor(
|
||||||
_colors[index].$1,
|
_colors[index].$1,
|
||||||
),
|
),
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
@@ -501,7 +501,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
width: 16,
|
width: 16,
|
||||||
height: 16,
|
height: 16,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: getColorFromGameColor(selectedColor!),
|
color: getColorFromAppColor(selectedColor!),
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:tallee/core/common.dart';
|
||||||
import 'package:tallee/core/enums.dart';
|
import 'package:tallee/core/enums.dart';
|
||||||
import 'package:tallee/data/models/match.dart';
|
import 'package:tallee/data/models/match.dart';
|
||||||
import 'package:tallee/data/models/player.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;
|
show translateStatisticTypeToString;
|
||||||
import 'package:tallee/presentation/widgets/tiles/statistics_tile.dart';
|
import 'package:tallee/presentation/widgets/tiles/statistics_tile.dart';
|
||||||
|
|
||||||
/// Build the [StatisticsTile] for a given [Statistic].
|
List<Color> _colorPalette = AppColor.values
|
||||||
|
.map((c) => getColorFromAppColor(c))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
/// Build the [StatisticsTile] for a given [Statistic].
|
||||||
Widget buildStatisticTile({
|
Widget buildStatisticTile({
|
||||||
required Statistic statistic,
|
required Statistic statistic,
|
||||||
required List<Match> matches,
|
required List<Match> matches,
|
||||||
@@ -272,24 +276,10 @@ IconData _getStatisticIcon({required StatisticType type}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The bar colors for the statistic tiles
|
|
||||||
const List<Color> _palette = <Color>[
|
|
||||||
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.
|
/// Returns a color from the palette based on the statistic's ID as random seed.
|
||||||
Color _getStatisticColor(Statistic stat) {
|
Color _getStatisticColor(Statistic stat) {
|
||||||
final seed = stat.id.hashCode;
|
final seed = stat.id.hashCode;
|
||||||
return _palette[seed.abs() % _palette.length];
|
return _colorPalette[seed.abs() % _colorPalette.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skeleton data */
|
/* Skeleton data */
|
||||||
@@ -308,7 +298,7 @@ Widget buildSkeletonStatisticTile({required BuildContext context}) {
|
|||||||
width: MediaQuery.sizeOf(context).width * 0.95,
|
width: MediaQuery.sizeOf(context).width * 0.95,
|
||||||
values: values,
|
values: values,
|
||||||
itemCount: count,
|
itemCount: count,
|
||||||
barColor: _palette[Random().nextInt(_palette.length)],
|
barColor: _colorPalette[Random().nextInt(_colorPalette.length)],
|
||||||
statistic: Statistic(
|
statistic: Statistic(
|
||||||
type: StatisticType.totalMatches,
|
type: StatisticType.totalMatches,
|
||||||
scopes: [StatisticScope.allPlayers],
|
scopes: [StatisticScope.allPlayers],
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class GameLabel extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final backgroundColor = getColorFromGameColor(color);
|
final backgroundColor = getColorFromAppColor(color);
|
||||||
final fontColor = backgroundColor.computeLuminance() > 0.5
|
final fontColor = backgroundColor.computeLuminance() > 0.5
|
||||||
? Colors.black
|
? Colors.black
|
||||||
: Colors.white;
|
: Colors.white;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class GameTile extends StatelessWidget {
|
|||||||
? (badgeColor!.computeLuminance() > 0.5 ? Colors.black : Colors.white)
|
? (badgeColor!.computeLuminance() > 0.5 ? Colors.black : Colors.white)
|
||||||
: Colors.white;
|
: Colors.white;
|
||||||
|
|
||||||
final gameColor = badgeColor ?? getColorFromGameColor(AppColor.orange);
|
final gameColor = badgeColor ?? getColorFromAppColor(AppColor.orange);
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
|||||||
Reference in New Issue
Block a user