Compare commits
3 Commits
b443230285
...
8c005d6e5e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c005d6e5e | ||
|
|
cc50e497c9 | ||
|
|
ae348499d4 |
@@ -17,47 +17,6 @@ class GameHistoryTile extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _GameHistoryTileState extends State<GameHistoryTile> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -101,7 +60,7 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
|
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
if (group != null)
|
if (group != null) ...[
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(
|
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(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -144,19 +103,22 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
color: Colors.amber,
|
color: Colors.amber,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Expanded(
|
||||||
|
child: Text(
|
||||||
'Winner: ${winner.name}',
|
'Winner: ${winner.name}',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
if (winner != null) const SizedBox(height: 12),
|
],
|
||||||
|
|
||||||
if (allPlayers.isNotEmpty) ...[
|
if (allPlayers.isNotEmpty) ...[
|
||||||
const Text(
|
const Text(
|
||||||
@@ -172,7 +134,6 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
spacing: 6,
|
spacing: 6,
|
||||||
runSpacing: 6,
|
runSpacing: 6,
|
||||||
children: allPlayers.map((player) {
|
children: allPlayers.map((player) {
|
||||||
final isWinner = winner != null && player.id == winner.id;
|
|
||||||
return TextIconTile(
|
return TextIconTile(
|
||||||
text: player.name,
|
text: player.name,
|
||||||
iconEnabled: false,
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user