2 Commits

Author SHA1 Message Date
7810443a00 Fix: SetState Error
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 39s
Pull Request Pipeline / lint (pull_request) Successful in 45s
2026-03-07 22:11:51 +01:00
27c6d8b293 Small corrections 2026-03-07 21:57:51 +01:00
3 changed files with 55 additions and 49 deletions

View File

@@ -58,7 +58,7 @@ class _MatchViewState extends State<MatchView> {
void initState() { void initState() {
super.initState(); super.initState();
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
loadGames(); loadMatches();
} }
@override @override
@@ -100,7 +100,7 @@ class _MatchViewState extends State<MatchView> {
adaptivePageRoute( adaptivePageRoute(
builder: (context) => MatchDetailView( builder: (context) => MatchDetailView(
match: matches[index], match: matches[index],
onMatchUpdate: loadGames, onMatchUpdate: loadMatches,
), ),
), ),
); );
@@ -123,7 +123,7 @@ class _MatchViewState extends State<MatchView> {
context, context,
adaptivePageRoute( adaptivePageRoute(
builder: (context) => builder: (context) =>
CreateMatchView(onWinnerChanged: loadGames), CreateMatchView(onWinnerChanged: loadMatches),
), ),
); );
}, },
@@ -134,8 +134,8 @@ class _MatchViewState extends State<MatchView> {
); );
} }
/// Loads the games from the database and sorts them by creation date. /// Loads the matches from the database and sorts them by creation date.
void loadGames() { void loadMatches() {
isLoading = true; isLoading = true;
Future.wait([ Future.wait([
db.matchDao.getAllMatches(), db.matchDao.getAllMatches(),

View File

@@ -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,8 +226,9 @@ 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) { _allPlayersFuture.then((loadedPlayers) {
if (!mounted) return;
setState(() { setState(() {
// If a list of available players is provided (even if empty), use that list. // If a list of available players is provided (even if empty), use that list.
if (widget.availablePlayers != null) { if (widget.availablePlayers != null) {
@@ -249,13 +252,17 @@ class _PlayerSelectionState extends State<PlayerSelection> {
allPlayers = [...loadedPlayers]; allPlayers = [...loadedPlayers];
if (widget.initialSelectedPlayers != null) { if (widget.initialSelectedPlayers != null) {
// Excludes already selected players from the suggested players list. // Excludes already selected players from the suggested players list.
suggestedPlayers = loadedPlayers.where((p) => !widget.initialSelectedPlayers!.any((ip) => ip.id == p.id)).toList(); suggestedPlayers = loadedPlayers
.where(
(p) => !widget.initialSelectedPlayers!.any(
(ip) => ip.id == p.id,
),
)
.toList();
// 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) => allPlayers.any( (p) => allPlayers.any((available) => available.id == p.id),
(available) => available.id == p.id,
),
) )
.toList(); .toList();
} else { } else {
@@ -267,7 +274,6 @@ 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 or failure.

View File

@@ -43,9 +43,9 @@ class _MatchTileState extends State<MatchTile> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final match = widget.match; final match = widget.match;
final group = widget.match.group; final group = match.group;
final winner = widget.match.winner; final winner = match.winner;
final players = [...widget.match.players] final players = [...match.players]
..sort((a, b) => a.name.compareTo(b.name)); ..sort((a, b) => a.name.compareTo(b.name));
final loc = AppLocalizations.of(context); final loc = AppLocalizations.of(context);