'Dynamic Icon value selector in Jetpack Compose

Is there a way to dynamically set an icon value in Jetpack Compose?

Example, instead of:

Icon(Icons.Filled.Print, "print")

I'd like to do:

Icon(Icons.Filled.(iconValue), iconValueName)


Solution 1:[1]

You can then use a when statement and select appropriate image vector.

when(imageStringFromWeb) {
    is "email" -> {
        Icon(Icons.Filled.Email, null)
    }
    ...
}

Edited to simplfy the code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1