loadJson method
Loads an object from a JSON file ('.db' file). If the file doesn't exist, returns null. Note: The file must contain a single JSON, which is NOT the default file-format for LocalPersist.
Implementation
Future<Object?>? loadJson() async {
_checkIfFileSystemIsTheSame();
File file = _file ?? await this.file();
if (!file.existsSync())
return null;
else {
Uint8List encoded;
try {
encoded = await file.readAsBytes();
} catch (error) {
if ((error is FileSystemException) && //
error.message.contains("No such file or directory")) return null;
rethrow;
}
Object? simpleObjs = decodeJson(encoded);
return simpleObjs;
}
}