load method

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

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).

Implementation

@override
Future<ByteData> load(String key) async {
  final span = _hub.getSpan()?.startChild(
        'file.read',
        description: 'AssetBundle.load: ${_fileName(key)}',
      );

  span?.setData('file.path', key);

  ByteData? data;
  try {
    data = await _bundle.load(key);
    _setDataLength(data, span);
    span?.status = SpanStatus.ok();
  } catch (exception) {
    span?.throwable = exception;
    span?.status = SpanStatus.internalError();
    rethrow;
  } finally {
    await span?.finish();
  }
  return data;
}