Passing Flutter icons to android java

257

You can pass the image name as a string to your android plugin and use AssetManager to get the path to as described in flutter documentation.

for example:

    val assetManager: AssetManager = registrar.context().assets
    val key: String = registrar.lookupKeyForAsset("image")
    val fd = assetManager.openFd(key)
    val image = BitmapFactory.decodeStream(fd.createInputStream())
Share:
257
Kaki Master Of Time
Author by

Kaki Master Of Time

Updated on December 18, 2022

Comments

  • Kaki Master Of Time
    Kaki Master Of Time over 1 year

    I am trying to find a way to pass parameters from my flutter/dart app to a plugin I am writing in java. My goal is to let the dart code pass a standard Icon as parameters to the plugin and the latter showing it in an ImageView. My attempts are to pass the IconData containing the font and the unicode for the icon as well as the hex color of that icon. On the the plugin side, there will be a retrieval of that icon using the IconData and applying the color via from the hex color.

    I can pass the arguments to the plugin like any other String argument but I didn't find a way to do the java part. I have tried creating Bitmaps and then changing their colors but that didn't work at all.

    I am asking if there is a known way to passing icons from dart to flutter especially when they are based on external fonts?

    • nvi9
      nvi9 about 4 years
      Something similar has been already asked eg. here: stackoverflow.com/questions/15210548/…
    • Kaki Master Of Time
      Kaki Master Of Time about 4 years
      @nvi9 yeah I saw those answers, it I still not the one I am looking for