load method
Loads a simple-object from a JSON file. If the file doesn't exist, returns null. A JSON can be a String, a number, null, true, false, '{' (a map) or ']' (a list). Note: The file must contain a single JSON, and it can't be empty. It can, however simple contain 'null' (without the quotes) which will return null.
Implementation
Future<Object?> load() 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;
}
}