From 9a0386f22d7c9059c745dfa2e0c1be76a1226758 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 19 Apr 2026 23:41:10 +0200 Subject: [PATCH] Added case for not fetching a player --- lib/data/dao/player_dao.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/data/dao/player_dao.dart b/lib/data/dao/player_dao.dart index 6d4cff7..5d46343 100644 --- a/lib/data/dao/player_dao.dart +++ b/lib/data/dao/player_dao.dart @@ -143,7 +143,7 @@ class PlayerDao extends DatabaseAccessor with _$PlayerDaoMixin { return rowsAffected > 0; } - /// Checks if a player with the given [id] exists in the database. + /// Checks if a player with the given [playerId] exists in the database. /// Returns `true` if the player exists, `false` otherwise. Future playerExists({required String playerId}) async { final query = select(playerTable)..where((p) => p.id.equals(playerId)); @@ -157,9 +157,11 @@ class PlayerDao extends DatabaseAccessor with _$PlayerDaoMixin { required String newName, }) async { // Get previous name and name count for the player before updating - final previousPlayerName = await (select( - playerTable, - )..where((p) => p.id.equals(playerId))).map((row) => row.name).getSingle(); + final previousPlayerName = + await (select(playerTable)..where((p) => p.id.equals(playerId))) + .map((row) => row.name) + .getSingleOrNull() ?? + ''; final previousNameCount = await getNameCount(name: previousPlayerName); await (update(playerTable)..where((p) => p.id.equals(playerId))).write( @@ -197,7 +199,7 @@ class PlayerDao extends DatabaseAccessor with _$PlayerDaoMixin { return count ?? 0; } - /// Retrieves the count of players with the given [name] in the database. + /// Retrieves the count of players with the given [name]. Future getNameCount({required String name}) async { final query = select(playerTable)..where((p) => p.name.equals(name)); final result = await query.get();