diff --git a/lib/presentation/widgets/tiles/match_tile.dart b/lib/presentation/widgets/tiles/match_tile.dart index ddc7887..6ac382a 100644 --- a/lib/presentation/widgets/tiles/match_tile.dart +++ b/lib/presentation/widgets/tiles/match_tile.dart @@ -40,12 +40,13 @@ class MatchTile extends StatefulWidget { } class _MatchTileState extends State { - late final List _allPlayers; + late List _allPlayers; @override void initState() { super.initState(); - _allPlayers = _getCombinedPlayers(); + _allPlayers = [...widget.match.players]; + _allPlayers.sort((a, b) => a.name.compareTo(b.name)); } @override @@ -93,7 +94,7 @@ class _MatchTileState extends State { const SizedBox(width: 6), Expanded( child: Text( - '${group.name} + ${widget.match.players.length}', + '${group.name}${getExtraPlayerCount()}', style: const TextStyle(fontSize: 14, color: Colors.grey), overflow: TextOverflow.ellipsis, ), @@ -236,21 +237,23 @@ class _MatchTileState extends State { } } - /// Retrieves all unique players associated with the match, - /// combining players from both the match and its group. - List _getCombinedPlayers() { - final allPlayers = []; - final playerIds = {}; + /// Counts how many players in the match are not part of the group + /// Returns the count as a string, or an empty string if there is no group + String getExtraPlayerCount() { + int count = 0; - // Add players from game.players - for (var player in widget.match.players) { - if (!playerIds.contains(player.id)) { - allPlayers.add(player); - playerIds.add(player.id); + final groupMembers = widget.match.group!.members; + final players = widget.match.players; + + for (var player in players) { + if (!groupMembers.any((member) => member.id == player.id)) { + count++; } } - allPlayers.sort((a, b) => a.name.compareTo(b.name)); - return allPlayers; + if (count == 0) { + return ''; + } + return ' + ${count.toString()}'; } }