I have a Box and some Text in it. The Text is actually just a number, which can be 1, 2, or 3 digits. On the one hand, I want to wrap the content to accommodate for the case where we get a 3 digit number (which would make the box wider), but on the other hand, if we get a 1 digit number, the box becomes very skinny and looks visually awkward.
I've tried Modifier.width(Int.dp) and Modifier.wrapContentWidth() and even a combination of the two, but can't get it to behave right. Is there a way in Compose to wrap the content, but with a minimum (default) width or height?
I'd rather not use an if - else statement on the input size if at all possible, since that would sort of defeat the purpose.
You may use the widthIn modifier to specify a minimum width, while allowing the element to expand further if necessary.
@Composable
fun Foo(){
Text(text = "1", modifier = Modifier.widthIn(min = 32.dp))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With