Merge pull request 'Ausgewählte Spieler durch Gruppe werden nicht aussortiert' (#124) from bug/113-ausgewählte-spieler-durch-gruppe-werden-nicht-aussortiert into development

Reviewed-on: #124
Reviewed-by: Mathis Kirchner <mathis.kirchner.mk@gmail.com>
This commit was merged in pull request #124.
This commit is contained in:
2026-01-02 20:22:45 +00:00
2 changed files with 29 additions and 17 deletions

View File

@@ -110,8 +110,10 @@ class _CreateMatchViewState extends State<CreateMatchView> {
]).then((result) async { ]).then((result) async {
groupsList = result[0] as List<Group>; groupsList = result[0] as List<Group>;
playerList = result[1] as List<Player>; playerList = result[1] as List<Player>;
setState(() {
filteredPlayerList = List.from(playerList);
});
}); });
filteredPlayerList = List.from(playerList);
} }
@override @override

View File

@@ -12,13 +12,13 @@ import 'package:provider/provider.dart';
class PlayerSelection extends StatefulWidget { class PlayerSelection extends StatefulWidget {
final Function(List<Player> value) onChanged; final Function(List<Player> value) onChanged;
final List<Player> availablePlayers; final List<Player>? availablePlayers;
final List<Player>? initialSelectedPlayers; final List<Player>? initialSelectedPlayers;
const PlayerSelection({ const PlayerSelection({
super.key, super.key,
required this.onChanged, required this.onChanged,
this.availablePlayers = const [], this.availablePlayers,
this.initialSelectedPlayers, this.initialSelectedPlayers,
}); });
@@ -56,17 +56,17 @@ class _PlayerSelectionState extends State<PlayerSelection> {
if (mounted) { if (mounted) {
_allPlayersFuture.then((loadedPlayers) { _allPlayersFuture.then((loadedPlayers) {
setState(() { setState(() {
// If a list of available players is provided, use that list. // If a list of available players is provided (even if empty), use that list.
if (widget.availablePlayers.isNotEmpty) { if (widget.availablePlayers != null) {
widget.availablePlayers.sort((a, b) => a.name.compareTo(b.name)); widget.availablePlayers!.sort((a, b) => a.name.compareTo(b.name));
allPlayers = [...widget.availablePlayers]; allPlayers = [...widget.availablePlayers!];
suggestedPlayers = [...allPlayers]; suggestedPlayers = [...allPlayers];
if (widget.initialSelectedPlayers != null) { if (widget.initialSelectedPlayers != null) {
// Ensures that only players available for selection are pre-selected. // Ensures that only players available for selection are pre-selected.
selectedPlayers = widget.initialSelectedPlayers! selectedPlayers = widget.initialSelectedPlayers!
.where( .where(
(p) => widget.availablePlayers.any( (p) => widget.availablePlayers!.any(
(available) => available.id == p.id, (available) => available.id == p.id,
), ),
) )
@@ -182,9 +182,6 @@ class _PlayerSelectionState extends State<PlayerSelection> {
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
/*
*/
Expanded( Expanded(
child: AppSkeleton( child: AppSkeleton(
enabled: isLoading, enabled: isLoading,
@@ -193,11 +190,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
replacement: TopCenteredMessage( replacement: TopCenteredMessage(
icon: Icons.info, icon: Icons.info,
title: 'Info', title: 'Info',
message: allPlayers.isEmpty message: _getInfoText(),
? 'No players created yet'
: (selectedPlayers.length == allPlayers.length)
? 'No more players to add'
: 'No players found with that name',
), ),
child: ListView.builder( child: ListView.builder(
itemCount: suggestedPlayers.length, itemCount: suggestedPlayers.length,
@@ -231,7 +224,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
} }
/// Adds a new player to the database from the search bar input. /// Adds a new player to the database from the search bar input.
/// Shows a snackbar indicating success xfor failure. /// Shows a snackbar indicating success or failure.
/// [context] - BuildContext to show the snackbar. /// [context] - BuildContext to show the snackbar.
void addNewPlayerFromSearch({required BuildContext context}) async { void addNewPlayerFromSearch({required BuildContext context}) async {
String playerName = _searchBarController.text.trim(); String playerName = _searchBarController.text.trim();
@@ -273,4 +266,21 @@ class _PlayerSelectionState extends State<PlayerSelection> {
); );
} }
} }
/// Determines the appropriate info text to display when no players
/// are available in the suggested players list.
String _getInfoText() {
if (allPlayers.isEmpty) {
// No players exist in the database
return 'No players created yet';
} else if (selectedPlayers.length == allPlayers.length ||
widget.availablePlayers?.isEmpty == true) {
// All players have been selected or
// available players list is provided but empty
return 'No more players to add';
} else {
// No players match the search query
return 'No players found with that name';
}
}
} }