Bearbeiten und Löschen von Matches #171
@@ -110,7 +110,9 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
|||||||
final bool nameMatches = player.name.toLowerCase().contains(
|
final bool nameMatches = player.name.toLowerCase().contains(
|
||||||
value.toLowerCase(),
|
value.toLowerCase(),
|
||||||
);
|
);
|
||||||
final bool isNotSelected = !selectedPlayers.any((p) => p.id == player.id);
|
final bool isNotSelected = !selectedPlayers.any(
|
||||||
|
(p) => p.id == player.id,
|
||||||
|
);
|
||||||
return nameMatches && isNotSelected;
|
return nameMatches && isNotSelected;
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
@@ -224,49 +226,53 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
|||||||
db.playerDao.getAllPlayers(),
|
db.playerDao.getAllPlayers(),
|
||||||
Future.delayed(Constants.MINIMUM_SKELETON_DURATION),
|
Future.delayed(Constants.MINIMUM_SKELETON_DURATION),
|
||||||
]).then((results) => results[0] as List<Player>);
|
]).then((results) => results[0] as List<Player>);
|
||||||
if (mounted) {
|
|
||||||
_allPlayersFuture.then((loadedPlayers) {
|
|
||||||
setState(() {
|
|
||||||
// If a list of available players is provided (even if empty), use that list.
|
|
||||||
if (widget.availablePlayers != null) {
|
|
||||||
widget.availablePlayers!.sort((a, b) => a.name.compareTo(b.name));
|
|
||||||
allPlayers = [...widget.availablePlayers!];
|
|
||||||
suggestedPlayers = [...allPlayers];
|
|
||||||
|
|
||||||
if (widget.initialSelectedPlayers != null) {
|
_allPlayersFuture.then((loadedPlayers) {
|
||||||
// Ensures that only players available for selection are pre-selected.
|
if (!mounted) return;
|
||||||
selectedPlayers = widget.initialSelectedPlayers!
|
setState(() {
|
||||||
.where(
|
// If a list of available players is provided (even if empty), use that list.
|
||||||
(p) => widget.availablePlayers!.any(
|
if (widget.availablePlayers != null) {
|
||||||
(available) => available.id == p.id,
|
widget.availablePlayers!.sort((a, b) => a.name.compareTo(b.name));
|
||||||
),
|
allPlayers = [...widget.availablePlayers!];
|
||||||
)
|
suggestedPlayers = [...allPlayers];
|
||||||
.toList();
|
|
||||||
}
|
if (widget.initialSelectedPlayers != null) {
|
||||||
} else {
|
// Ensures that only players available for selection are pre-selected.
|
||||||
// Otherwise, use the loaded players from the database.
|
selectedPlayers = widget.initialSelectedPlayers!
|
||||||
loadedPlayers.sort((a, b) => a.name.compareTo(b.name));
|
.where(
|
||||||
allPlayers = [...loadedPlayers];
|
(p) => widget.availablePlayers!.any(
|
||||||
if (widget.initialSelectedPlayers != null) {
|
(available) => available.id == p.id,
|
||||||
// Excludes already selected players from the suggested players list.
|
),
|
||||||
suggestedPlayers = loadedPlayers.where((p) => !widget.initialSelectedPlayers!.any((ip) => ip.id == p.id)).toList();
|
)
|
||||||
// Ensures that only players available for selection are pre-selected.
|
.toList();
|
||||||
selectedPlayers = widget.initialSelectedPlayers!
|
|
||||||
.where(
|
|
||||||
(p) => allPlayers.any(
|
|
||||||
(available) => available.id == p.id,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList();
|
|
||||||
} else {
|
|
||||||
// If no initial selection, all loaded players are suggested.
|
|
||||||
suggestedPlayers = [...loadedPlayers];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
isLoading = false;
|
} else {
|
||||||
});
|
// Otherwise, use the loaded players from the database.
|
||||||
|
loadedPlayers.sort((a, b) => a.name.compareTo(b.name));
|
||||||
|
allPlayers = [...loadedPlayers];
|
||||||
|
if (widget.initialSelectedPlayers != null) {
|
||||||
|
// Excludes already selected players from the suggested players list.
|
||||||
|
suggestedPlayers = loadedPlayers
|
||||||
|
.where(
|
||||||
|
(p) => !widget.initialSelectedPlayers!.any(
|
||||||
|
(ip) => ip.id == p.id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
// Ensures that only players available for selection are pre-selected.
|
||||||
|
selectedPlayers = widget.initialSelectedPlayers!
|
||||||
|
.where(
|
||||||
|
(p) => allPlayers.any((available) => available.id == p.id),
|
||||||
|
flixcoo marked this conversation as resolved
|
|||||||
|
)
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
// If no initial selection, all loaded players are suggested.
|
||||||
|
suggestedPlayers = [...loadedPlayers];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a new player to the database from the search bar input.
|
/// Adds a new player to the database from the search bar input.
|
||||||
|
|||||||
Reference in New Issue
Block a user
was geht hier ab? wieso changes?
Da kam dieser Error, den du hattest her. Da habe ich ein if statement entfernt, dadurch hat sich alles verschoben und wird als Änderung markiert. Effektiv habe ich nur ein
if(mounted){...}durch einif(!mounted) return;ersetzt