Added function gameExistsInGameList
This commit is contained in:
@@ -15,14 +15,9 @@ class GameManager extends ChangeNotifier {
|
|||||||
notifyListeners(); // Propagate session changes
|
notifyListeners(); // Propagate session changes
|
||||||
});
|
});
|
||||||
gameList.add(session);
|
gameList.add(session);
|
||||||
print(
|
|
||||||
'[game_manager.dart] Added game session: ${session.gameTitle} at ${session.createdAt}');
|
|
||||||
gameList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
gameList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||||
print(
|
|
||||||
'[game_manager.dart] Sorted game sessions by creation date. Total sessions: ${gameList.length}');
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
await LocalStorageService.saveGameSessions();
|
await LocalStorageService.saveGameSessions();
|
||||||
print('[game_manager.dart] Saved game sessions to local storage.');
|
|
||||||
return gameList.indexOf(session);
|
return gameList.indexOf(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,12 +35,17 @@ class GameManager extends ChangeNotifier {
|
|||||||
/// Removes a game session by its ID.
|
/// 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
|
/// 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.
|
/// in the `gameList`, and then calls `removeGameSessionByIndex` with that index.
|
||||||
bool removeGameSessionById(String id) {
|
void removeGameSessionById(String id) {
|
||||||
final int index =
|
final int index =
|
||||||
gameList.indexWhere((session) => session.id.toString() == id);
|
gameList.indexWhere((session) => session.id.toString() == id);
|
||||||
if (index == -1) return false;
|
if (index == -1) return;
|
||||||
removeGameSessionByIndex(index);
|
removeGameSessionByIndex(index);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
bool gameExistsInGameList(String id) {
|
||||||
|
return gameList.any((session) => session.id.toString() == id) == -1
|
||||||
|
? false
|
||||||
|
: true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user