3 Commits

Author SHA1 Message Date
fc6c74b377 Merge pull request 'Entfernen von Ausgewählten Spielern, fügt sie nicht wieder zur Auswahl hinzu' (#117) from bug/116-entfernen-von-ausgewählten-spielern-fuegt-sie-nicht-wieder-zur-auswahl-hinzu into development
Reviewed-on: #117
Reviewed-by: Mathis Kirchner <mathis.kirchner.mk@gmail.com>
2026-01-01 16:50:07 +00:00
15d09f381a New created players will be added now at the front too
All checks were successful
Pull Request Pipeline / lint (pull_request) Successful in 2m9s
Pull Request Pipeline / test (pull_request) Successful in 2m8s
2026-01-01 17:47:15 +01:00
bbb7914fc5 Updated sorting logic & added comments
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m0s
Pull Request Pipeline / lint (pull_request) Successful in 2m5s
2026-01-01 16:39:57 +01:00

View File

@@ -149,18 +149,24 @@ class _PlayerSelectionState extends State<PlayerSelection> {
onIconTap: () { onIconTap: () {
setState(() { setState(() {
// Removes the player from the selection and notifies the parent. // Removes the player from the selection and notifies the parent.
selectedPlayers.remove(player);
widget.onChanged([...selectedPlayers]);
// Get the current search query
final currentSearch = _searchBarController final currentSearch = _searchBarController
.text .text
.toLowerCase(); .toLowerCase();
selectedPlayers.remove(player);
widget.onChanged([...selectedPlayers]);
// If the player matches the current search query (or search is empty), // If the player matches the current search query (or search is empty),
// they are added back to the suggestions and the list is re-sorted. // they are added back to the `suggestedPlayers` and the list is re-sorted.
if (currentSearch.isEmpty || if (currentSearch.isEmpty ||
player.name.toLowerCase().contains( player.name.toLowerCase().contains(
currentSearch, currentSearch,
)) { )) {
suggestedPlayers.add(player); suggestedPlayers.add(player);
suggestedPlayers.sort(
(a, b) => a.name.compareTo(b.name),
);
} }
}); });
}, },
@@ -200,11 +206,15 @@ class _PlayerSelectionState extends State<PlayerSelection> {
text: suggestedPlayers[index].name, text: suggestedPlayers[index].name,
onPressed: () { onPressed: () {
setState(() { setState(() {
// If the player is not already selected
if (!selectedPlayers.contains( if (!selectedPlayers.contains(
suggestedPlayers[index], suggestedPlayers[index],
)) { )) {
selectedPlayers.add(suggestedPlayers[index]); // Add to player to the front of the selectedPlayers
selectedPlayers.insert(0, suggestedPlayers[index]);
// Notify the parent widget of the change
widget.onChanged([...selectedPlayers]); widget.onChanged([...selectedPlayers]);
// Remove the player from the suggestedPlayers
suggestedPlayers.remove(suggestedPlayers[index]); suggestedPlayers.remove(suggestedPlayers[index]);
} }
}); });
@@ -221,7 +231,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 or failure. /// Shows a snackbar indicating success xfor 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();
@@ -229,7 +239,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
bool success = await db.playerDao.addPlayer(player: createdPlayer); bool success = await db.playerDao.addPlayer(player: createdPlayer);
if (!context.mounted) return; if (!context.mounted) return;
if (success) { if (success) {
selectedPlayers.add(createdPlayer); selectedPlayers.insert(0, createdPlayer);
widget.onChanged([...selectedPlayers]); widget.onChanged([...selectedPlayers]);
allPlayers.add(createdPlayer); allPlayers.add(createdPlayer);
setState(() { setState(() {