Flutter: How are images passed to native side?

Viewed 289

I am building a plugin and need to make use of images (like Image.asset or Image.file) and need to pass them to my native plugin. However, I could not find a decent way to pass these. Does anyone know how to achieve that and how these objects are used natively in general?

1 Answers

You can pass the asset path and read it via Flutter:

  1. Pass the asset path through MethodChannel
  2. Look for the asset using it's path:
AssetManager assetManager = registrar.context().getAssets();
String key = registrar.lookupKeyForAsset("icons/heart.png");
AssetFileDescriptor fd = assetManager.openFd(key);

Flutter docs

Related