loadAsset static method

Future<ByteData?> loadAsset(
  1. String key
)

Implementation

static Future<ByteData?> loadAsset(String key) async{
  final String assetFolderPath = Platform.environment['UNIT_TEST_ASSETS']!;
  final String prefix =  'packages/${Platform.environment['APP_NAME']}/';
  final String channel = _FLUTTER_ASSETS_CHANNEL;

  File asset = isNullOrEmpty(assetFolderPath) ? File(key) : File(path.join(assetFolderPath, key));

  if (!asset.existsSync()) {
    if (!key.startsWith(prefix)) {
      return null;
    }

    key = key.replaceFirst(prefix, '');
    asset = !isNullOrEmpty(assetFolderPath) ? File(path.join(assetFolderPath, key)) : File(key);
    if (!asset.existsSync()) {
      return null;
    }
  }

  final Uint8List encoded = Uint8List.fromList(asset.readAsBytesSync());
  return Future<ByteData>.value(encoded.buffer.asByteData());
}