Updated import method
This commit is contained in:
@@ -111,7 +111,7 @@ class LocalStorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Opens the file picker to import a JSON file and loads the game data from it.
|
/// Opens the file picker to import a JSON file and loads the game data from it.
|
||||||
static Future<bool> importJsonFile() async {
|
static Future<int> importJsonFile() async {
|
||||||
final result = await FilePicker.platform.pickFiles(
|
final result = await FilePicker.platform.pickFiles(
|
||||||
dialogTitle: 'Wähle eine Datei mit Spieldaten aus',
|
dialogTitle: 'Wähle eine Datei mit Spieldaten aus',
|
||||||
type: FileType.custom,
|
type: FileType.custom,
|
||||||
@@ -121,14 +121,14 @@ class LocalStorageService {
|
|||||||
if (result == null) {
|
if (result == null) {
|
||||||
print(
|
print(
|
||||||
'[local_storage_service.dart] Der Filepicker-Dialog wurde abgebrochen');
|
'[local_storage_service.dart] Der Filepicker-Dialog wurde abgebrochen');
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final jsonString = await _readFileContent(result.files.single);
|
final jsonString = await _readFileContent(result.files.single);
|
||||||
|
|
||||||
if (!await validateJsonSchema(jsonString)) {
|
if (!await validateJsonSchema(jsonString)) {
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
final jsonData = json.decode(jsonString) as List<dynamic>;
|
final jsonData = json.decode(jsonString) as List<dynamic>;
|
||||||
gameManager.gameList = jsonData
|
gameManager.gameList = jsonData
|
||||||
@@ -137,15 +137,16 @@ class LocalStorageService {
|
|||||||
.toList();
|
.toList();
|
||||||
print(
|
print(
|
||||||
'[local_storage_service.dart] Die Datei wurde erfolgreich Importiertn');
|
'[local_storage_service.dart] Die Datei wurde erfolgreich Importiertn');
|
||||||
return true;
|
await saveGameSessions();
|
||||||
|
return 1;
|
||||||
} on FormatException catch (e) {
|
} on FormatException catch (e) {
|
||||||
print(
|
print(
|
||||||
'[local_storage_service.dart] Ungültiges JSON-Format. Exception: $e');
|
'[local_storage_service.dart] Ungültiges JSON-Format. Exception: $e');
|
||||||
return false;
|
return -2;
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
print(
|
print(
|
||||||
'[local_storage_service.dart] Fehler beim Dateizugriff. Exception: $e');
|
'[local_storage_service.dart] Fehler beim Dateizugriff. Exception: $e');
|
||||||
return false;
|
return -3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user