loadString method
Retrieve a string from the asset bundle.
Throws an exception if the asset is not found.
If the cache
argument is set to false, then the data will not be
cached, and reading the data may bypass the cache. This is useful if the
caller is going to be doing its own caching. (It might not be cached if
it's set to true either, that depends on the asset bundle
implementation.)
Implementation
Future<String> loadString(String key, { bool cache = true }) async {
final ByteData data = await load(key);
if (data == null)
throw FlutterError('Unable to load asset: $key');
if (data.lengthInBytes < 10 * 1024) {
// 10KB takes about 3ms to parse on a Pixel 2 XL.
// See: https://github.com/dart-lang/sdk/issues/31954
return utf8.decode(data.buffer.asUint8List());
}
return compute(_utf8decode, data, debugLabel: 'UTF8 decode for "$key"');
}