RiveFile.import constructor

RiveFile.import(
  1. ByteData bytes, {
  2. FileAssetLoader? assetLoader,
  3. ObjectGenerator? objectGenerator,
  4. bool loadCdnAssets = true,
})

Imports a Rive file from an array of bytes.

Provide an assetLoader to load assets from a custom location (out of band assets). See CallbackAssetLoader for an example.

Set loadCdnAssets to false to disable loading assets from the CDN.

Whether an assets is embedded/cdn/referenced is determined by the Rive file - as set in the editor.

Loading assets documentation: https://rive.app/community/doc/loading-assets/doct4wVHGPgC

Provide an objectGenerator if you want to override any built-in Rive types.

Will throw RiveFormatErrorException if data is malformed. Will throw RiveUnsupportedVersionException if the version is not supported.

Implementation

factory RiveFile.import(
  ByteData bytes, {
  FileAssetLoader? assetLoader,
  ObjectGenerator? objectGenerator,
  bool loadCdnAssets = true,
}) {
  // TODO: in the next major version add an assert here to make this a
  // requirement
  if (!_initializedText) {
    debugPrint('''Rive: RiveFile.import called before RiveFile.initialize()

Consider calling `await RiveFile.initialize()` before using `RiveFile.import`''');
  }

  var reader = BinaryReader(bytes);
  return RiveFile._(
    reader,
    RuntimeHeader.read(reader),
    objectGenerator,
    FallbackAssetLoader(
      [
        if (assetLoader != null) assetLoader,
        if (loadCdnAssets) CDNAssetLoader(),
      ],
    ),
  );
}