Question:
I want create a simple button with 3 predefined sizes, I’m adding an enum param on my Compose view and depending on it I’m trying to set one of this predefined sizes as the width and height.My enum looks like this:
Answer:
When you call functions on a modifier, those functions don’t mutate the original modifier, instead they return a new (combined) modifier as their result, so you have to save the result from yourwhen
expression into a local value and then pass that value as the modifier
parameter to the Button
composable.You also have to chain the function calls to
.width()
and to .height()
inside the when expression (inside each case blocks).With all those changes you would get something like this
If you have better answer, please add a comment about this, thank you!