load method
Reads the file, treating "no file" as "an empty file".
A malformed file is treated the same way rather than raised. This is the file an application reads before it can show the user anything, so a parse error here would be a launch failure with no surface to report it on — and the content is by definition device-local and reconstructible.
Implementation
Future<void> load() async {
_values.clear();
_loaded = true;
Uint8List bytes;
try {
bytes = await storage.readBytes(locator);
_head = await storage.headOf(locator);
} on TomStorageException {
_head = null;
return;
}
Object? decoded;
try {
decoded = tomYamlToPlain(yaml.loadYaml(utf8.decode(bytes)));
} on FormatException {
return;
}
if (decoded is Map) {
_values.addAll(decoded.cast<String, Object?>());
}
}