players cant be null
Some checks failed
Pull Request Pipeline / test (pull_request) Failing after 40s
Pull Request Pipeline / lint (pull_request) Failing after 44s

This commit is contained in:
gelbeinhalb
2026-02-01 18:23:58 +01:00
parent dbef735a82
commit 7aba8554c0
7 changed files with 46 additions and 61 deletions

View File

@@ -63,7 +63,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
int selectedGameIndex = -1;
/// The currently selected players
List<Player>? selectedPlayers;
List<Player> selectedPlayers = [];
@override
void initState() {
@@ -178,7 +178,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
Expanded(
child: PlayerSelection(
key: ValueKey(selectedGroup?.id ?? 'no_group'),
initialSelectedPlayers: selectedPlayers ?? [],
initialSelectedPlayers: selectedPlayers,
availablePlayers: filteredPlayerList,
onChanged: (value) {
setState(() {
@@ -259,6 +259,6 @@ class _CreateMatchViewState extends State<CreateMatchView> {
/// - Either a group is selected OR at least 2 players are selected
bool _enableCreateGameButton() {
return (selectedGroup != null ||
(selectedPlayers != null && selectedPlayers!.length > 1));
(selectedPlayers.length > 1));
}
}

View File

@@ -153,12 +153,10 @@ class _MatchResultViewState extends State<MatchResultView> {
List<Player> getAllPlayers(Match match) {
List<Player> players = [];
if (match.group == null && match.players != null) {
players = [...match.players!];
} else if (match.group != null && match.players != null) {
players = [...match.players!, ...match.group!.members];
if (match.group == null) {
players = [...match.players];
} else {
players = [...match.group!.members];
players = [...match.players, ...match.group!.members];
}
players.sort((a, b) => a.name.compareTo(b.name));

View File

@@ -202,19 +202,17 @@ class _StatisticsViewState extends State<StatisticsView> {
}
}
}
if (match.players != null) {
final members = match.players!.map((p) => p.id).toList();
for (var playerId in members) {
final index = matchCounts.indexWhere((entry) => entry.$1 == playerId);
// -1 means player not found in matchCounts
if (index != -1) {
final current = matchCounts[index].$2;
final members = match.players.map((p) => p.id).toList();
for (var playerId in members) {
final index = matchCounts.indexWhere((entry) => entry.$1 == playerId);
// -1 means player not found in matchCounts
if (index != -1) {
final current = matchCounts[index].$2;
matchCounts[index] = (playerId, current + 1);
} else {
matchCounts.add((playerId, 1));
}
}
}
}
// Adding all players with zero matches

View File

@@ -91,7 +91,7 @@ class _MatchTileState extends State<MatchTile> {
const SizedBox(width: 6),
Expanded(
child: Text(
'${group.name}${widget.match.players != null ? ' + ${widget.match.players?.length}' : ''}',
'${group.name} + ${widget.match.players.length}',
style: const TextStyle(fontSize: 14, color: Colors.grey),
overflow: TextOverflow.ellipsis,
),
@@ -106,7 +106,7 @@ class _MatchTileState extends State<MatchTile> {
const SizedBox(width: 6),
Expanded(
child: Text(
'${widget.match.players!.length} ${loc.players}',
'${widget.match.players.length} ${loc.players}',
style: const TextStyle(fontSize: 14, color: Colors.grey),
overflow: TextOverflow.ellipsis,
),
@@ -241,12 +241,10 @@ class _MatchTileState extends State<MatchTile> {
final playerIds = <String>{};
// Add players from game.players
if (widget.match.players != null) {
for (var player in widget.match.players!) {
if (!playerIds.contains(player.id)) {
allPlayers.add(player);
playerIds.add(player.id);
}
for (var player in widget.match.players) {
if (!playerIds.contains(player.id)) {
allPlayers.add(player);
playerIds.add(player.id);
}
}