I have an image in the assets folder of my Flutter project. It’s accessible in the Flutter app, but I want to access it from the native side (Kotlin side) of the app. I searched about it in the Flutter docs and found this:
https://docs.flutter.dev/ui/assets/assets-and-images#sharing-assets-with-the-underlying-platform
AssetManager assetManager = registrar.context().getAssets();
String key = registrar.lookupKeyForAsset("icons/heart.png");
AssetFileDescriptor fd = assetManager.openFd(key);
I do not know what the registrar object is and how I can use that on the Kotlin side.
I saw the question on Stack Overflow, but it uses a Flutter plugin, which I do not want to use:
How *Exactly* to Access Flutter Assets From Within Android Java *Plugin* Platform Code?
I also saw the question below, and its answer uses the flutterInjector object, which is currently deprecated and removed from Flutter, so it cannot be accessed in the current version:
Is there a way to access Flutter resources from native code?
Henry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.