From 4e43ead072888b2f36514eac810105b15dec1e40 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 1 Jul 2025 22:22:56 +0200 Subject: [PATCH] Updated import method --- lib/services/local_storage_service.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/services/local_storage_service.dart b/lib/services/local_storage_service.dart index e3fddcc..eafcdc4 100644 --- a/lib/services/local_storage_service.dart +++ b/lib/services/local_storage_service.dart @@ -111,7 +111,7 @@ class LocalStorageService { } /// Opens the file picker to import a JSON file and loads the game data from it. - static Future importJsonFile() async { + static Future importJsonFile() async { final result = await FilePicker.platform.pickFiles( dialogTitle: 'Wähle eine Datei mit Spieldaten aus', type: FileType.custom, @@ -121,14 +121,14 @@ class LocalStorageService { if (result == null) { print( '[local_storage_service.dart] Der Filepicker-Dialog wurde abgebrochen'); - return false; + return 0; } try { final jsonString = await _readFileContent(result.files.single); if (!await validateJsonSchema(jsonString)) { - return false; + return -1; } final jsonData = json.decode(jsonString) as List; gameManager.gameList = jsonData @@ -137,15 +137,16 @@ class LocalStorageService { .toList(); print( '[local_storage_service.dart] Die Datei wurde erfolgreich Importiertn'); - return true; + await saveGameSessions(); + return 1; } on FormatException catch (e) { print( '[local_storage_service.dart] Ungültiges JSON-Format. Exception: $e'); - return false; + return -2; } on Exception catch (e) { print( '[local_storage_service.dart] Fehler beim Dateizugriff. Exception: $e'); - return false; + return -3; } }