From a803dc36d7e2270badfa6f9f457432e6106e0457 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Thu, 21 May 2026 19:54:46 +0200 Subject: [PATCH] fix: sorted games --- .../create_match/choose_game_view.dart | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart b/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart index 3c51cab..34f9be0 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart @@ -51,6 +51,9 @@ class _ChooseGameViewState extends State { /// Games filtered according to the current search query late List filteredGames; + List get games => + widget.games..sort((a, b) => a.name.compareTo(b.name)); + @override void initState() { db = Provider.of(context, listen: false); @@ -59,7 +62,7 @@ class _ChooseGameViewState extends State { selectedGameId = widget.initialGameId; // Start with all games visible - filteredGames = List.from(widget.games); + filteredGames = List.from(games); super.initState(); } @@ -77,9 +80,7 @@ class _ChooseGameViewState extends State { Navigator.of(context).pop( selectedGameId == '' ? null - : widget.games.firstWhere( - (game) => game.id == selectedGameId, - ), + : games.firstWhere((game) => game.id == selectedGameId), ); }, ), @@ -99,7 +100,7 @@ class _ChooseGameViewState extends State { ); if (result != null && result.game != null) { setState(() { - widget.games.insert(0, result.game); + games.insert(0, result.game); }); _refreshFromSource(); } @@ -139,7 +140,7 @@ class _ChooseGameViewState extends State { child: Visibility( visible: filteredGames.isNotEmpty, replacement: Visibility( - visible: widget.games.isNotEmpty, + visible: games.isNotEmpty, replacement: TopCenteredMessage( icon: Icons.info, title: loc.info, @@ -190,7 +191,7 @@ class _ChooseGameViewState extends State { ); if (result != null && result.game != null) { // Find the index in the original list to mutate - final originalIndex = widget.games.indexWhere( + final originalIndex = games.indexWhere( (g) => g.id == game.id, ); if (originalIndex == -1) { @@ -202,12 +203,12 @@ class _ChooseGameViewState extends State { if (selectedGameId == game.id) { selectedGameId = ''; } - widget.games.removeAt(originalIndex); + games.removeAt(originalIndex); widget.onGamesUpdated?.call(); }); } else { setState(() { - widget.games[originalIndex] = result.game; + games[originalIndex] = result.game; }); } _refreshFromSource(); @@ -229,13 +230,13 @@ class _ChooseGameViewState extends State { final q = query.toLowerCase().trim(); if (q.isEmpty) { setState(() { - filteredGames = List.from(widget.games); + filteredGames = List.from(games); }); return; } setState(() { - filteredGames = widget.games.where((game) { + filteredGames = games.where((game) { final name = game.name.toLowerCase(); final description = game.description.toLowerCase(); return name.contains(q) || description.contains(q);