load method Null safety
- String key
override
Retrieve a binary resource from the asset bundle as a data stream.
Throws an exception if the asset is not found.
Implementation
@override
Future<ByteData> load(String key) async {
final HttpClientRequest request = await _httpClient.getUrl(_urlFromKey(key));
final HttpClientResponse response = await request.close();
if (response.statusCode != HttpStatus.ok) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Unable to load asset: $key'),
IntProperty('HTTP status code', response.statusCode),
]);
}
final Uint8List bytes = await consolidateHttpClientResponseBytes(response);
return bytes.buffer.asByteData();
}