3 Commits

Author SHA1 Message Date
gelbeinhalb
8c005d6e5e fix possible render overflow
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m9s
Pull Request Pipeline / lint (pull_request) Successful in 2m10s
2025-11-27 17:06:32 +01:00
gelbeinhalb
cc50e497c9 merge duplicate if statements for group and winner sections 2025-11-27 17:04:08 +01:00
gelbeinhalb
ae348499d4 moved functionality methods to the bottom of the file 2025-11-27 17:00:13 +01:00

View File

@@ -17,47 +17,6 @@ class GameHistoryTile extends StatefulWidget {
}
class _GameHistoryTileState extends State<GameHistoryTile> {
String _formatDate(DateTime dateTime) {
final now = DateTime.now();
final difference = now.difference(dateTime);
if (difference.inDays == 0) {
return 'Today at ${DateFormat('HH:mm').format(dateTime)}';
} else if (difference.inDays == 1) {
return 'Yesterday at ${DateFormat('HH:mm').format(dateTime)}';
} else if (difference.inDays < 7) {
return '${difference.inDays} days ago';
} else {
return DateFormat('MMM d, yyyy').format(dateTime);
}
}
List<dynamic> _getAllPlayers() {
final allPlayers = <dynamic>[];
final playerIds = <String>{};
// Add players from game.players
if (widget.game.players != null) {
for (var player in widget.game.players!) {
if (!playerIds.contains(player.id)) {
allPlayers.add(player);
playerIds.add(player.id);
}
}
}
// Add players from game.group.players
if (widget.game.group?.members != null) {
for (var player in widget.game.group!.members) {
if (!playerIds.contains(player.id)) {
allPlayers.add(player);
playerIds.add(player.id);
}
}
}
return allPlayers;
}
@override
Widget build(BuildContext context) {
@@ -101,7 +60,7 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
const SizedBox(height: 8),
if (group != null)
if (group != null) ...[
Row(
children: [
const Icon(
@@ -122,10 +81,10 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
),
],
),
const SizedBox(height: 12),
],
if (group != null) const SizedBox(height: 12),
if (winner != null)
if (winner != null) ...[
Container(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
decoration: BoxDecoration(
@@ -144,19 +103,22 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
color: Colors.amber,
),
const SizedBox(width: 8),
Text(
Expanded(
child: Text(
'Winner: ${winner.name}',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.white,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
),
if (winner != null) const SizedBox(height: 12),
const SizedBox(height: 12),
],
if (allPlayers.isNotEmpty) ...[
const Text(
@@ -172,7 +134,6 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
spacing: 6,
runSpacing: 6,
children: allPlayers.map((player) {
final isWinner = winner != null && player.id == winner.id;
return TextIconTile(
text: player.name,
iconEnabled: false,
@@ -184,4 +145,47 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
),
);
}
String _formatDate(DateTime dateTime) {
final now = DateTime.now();
final difference = now.difference(dateTime);
if (difference.inDays == 0) {
return 'Today at ${DateFormat('HH:mm').format(dateTime)}';
} else if (difference.inDays == 1) {
return 'Yesterday at ${DateFormat('HH:mm').format(dateTime)}';
} else if (difference.inDays < 7) {
return '${difference.inDays} days ago';
} else {
return DateFormat('MMM d, yyyy').format(dateTime);
}
}
List<dynamic> _getAllPlayers() {
final allPlayers = <dynamic>[];
final playerIds = <String>{};
// Add players from game.players
if (widget.game.players != null) {
for (var player in widget.game.players!) {
if (!playerIds.contains(player.id)) {
allPlayers.add(player);
playerIds.add(player.id);
}
}
}
// Add players from game.group.players
if (widget.game.group?.members != null) {
for (var player in widget.game.group!.members) {
if (!playerIds.contains(player.id)) {
allPlayers.add(player);
playerIds.add(player.id);
}
}
}
return allPlayers;
}
}