From a756c493970d62c1563c50c9cd31c2657894b34f Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Thu, 3 Jul 2025 11:53:30 +0200 Subject: [PATCH] Added function getGameSessionIndexById() and renamed removeGameSessionByIndex() --- lib/data/game_manager.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/data/game_manager.dart b/lib/data/game_manager.dart index 94b6287..f00d73c 100644 --- a/lib/data/game_manager.dart +++ b/lib/data/game_manager.dart @@ -30,12 +30,19 @@ class GameManager extends ChangeNotifier { /// Takes a [index] as input. It then removes the session at the specified index from the `gameList`, /// sorts the list in descending order based on the creation date, and notifies listeners of the change. /// It also saves the updated game sessions to local storage. - void removeGameSession(int index) { + void removeGameSessionByIndex(int index) { gameList[index].removeListener(notifyListeners); gameList.removeAt(index); notifyListeners(); LocalStorageService.saveGameSessions(); } + + /// Removes a game session by its ID. + /// Takes a String [id] as input. It finds the index of the game session with the matching ID + /// in the `gameList`, and then calls `removeGameSessionByIndex` with that index. + int getGameSessionIndexById(String id) { + return gameList.indexWhere((session) => session.id.toString() == id); + } } final gameManager = GameManager();