loadStructuredData<T> method
Retrieve a string from the asset bundle, parse it with the given function, and return that function's result.
The result is not cached by the default implementation; the parser is run each time the resource is fetched. However, some subclasses may implement caching (notably, subclasses of CachingAssetBundle).
Implementation
@override
Future<T> loadStructuredData<T>(
String key,
Future<T> Function(String value) parser,
) {
// `containsKey` rather than a null check: a parser that legitimately
// produces null would otherwise be re-run on every call forever.
if (_structured.containsKey(key)) {
return SynchronousFuture(_structured[key] as T);
}
// `cache: false` for the same reason the SDK passes it: what is worth
// keeping is the parsed value, not the string it was parsed from. Failures
// cache nothing, so a read that threw is retried rather than remembered.
return loadString(
key,
cache: false,
).then(parser).then((value) => _structured[key] = value);
}