load method

  1. @override
Future<ByteData> load(
  1. String key

Retrieve a binary resource from the asset bundle as a data stream.

Throws an exception if the asset is not found.

The returned ByteData can be converted to a Uint8List (a list of bytes) using Uint8List.sublistView. Lists of bytes can be used with APIs that accept Uint8List objects, such as decodeImageFromList, as well as any API that accepts a List<int>, such as File.writeAsBytes or Utf8Codec.decode (accessible via utf8).


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>[
      IntProperty('HTTP status code', response.statusCode),
  final Uint8List bytes = await consolidateHttpClientResponseBytes(response);
  return ByteData.sublistView(bytes);