Skip to content

[rive_native] Image Replacement Issue in rive_native #466

@BlockRen

Description

@BlockRen

Image Replacement Not Working Correctly in rive_native

Description:
In rive_native, I am unable to replace images correctly in a Rive file. The same Rive animation file works fine in rive_common. In rive_native, the reader.data! passed to asset.decode(reader.data!) is different, but the final result always shows the same image.

/// Decode rive file
Future<void> loadArtBoard(Uint8List byteData) async {
  rive.File? riveFile = await rive.File.decode(
    byteData,
    riveFactory: rive.Factory.rive,
    assetLoader: imageReplace,
  );
  if (riveFile == null) {
    return;
  }
  ...
}

bool imageReplace(rive.FileAsset asset, Uint8List? bytes) {
  final imageName = imageReplaceMap[asset.name];
  if (imageName == null) {
    return false;
  }
  // Replace image
  ImgReader.readFile(imageName).then((reader) {
    if (reader == null || reader.data == null) {
      return;
    }
    asset.decode(reader.data!).then((success) {
      debugPrint(">>> Rive Image Replace: $imageName, ${reader.data!.length}");
    });
  });
  return true;
}

Is there any issue with the way images are being replaced or decoded in rive_native? Any help would be appreciated.

By the way, it seems that the assetLoader should be able to support async methods, as asset.decode is also a time-consuming operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions