``` BadgeBox(badgeContent = { Text(value) }) {...
# compose
m
Copy code
BadgeBox(badgeContent = { Text(value) }) {
         //whatever
     }
I have a
BadgeBox
like this, but if the value is
0
, I want to badge to be hidden. If I pass null to
badgeContent
, the circle still shows but with nothing in it. How do I hide it completely while still showing the inner content?
a
how about an
if
around the badge box?
Copy code
if (value != null && value > 0) }
     BadgeBox(badgeContent = { Text(value) }) {
         //whatever
}
m
but then the
whatever
won’t show either. i still need the inner content to be displayed 🙂
a
That seems to get a bit tricky. I guess you could have that in an else, as a separate composable and just either wrap it in the BadgeBox or not, but it does get a bit more repetitive that way.
m
yeah true. thanks for your help. 🙂 this seems like a big flaw in the component. it should be easily hideable!
👍 1
l
Copy code
val content = { 
    // whatever
}

if (value != null && value > 0) {
     BadgeBox(badgeContent = { Text(value) }) {
    content()
} else {
    content()
}
Is probably the best way here
But note that this API has been changed in recent versions to no longer have this issue, so I would recommend upgrading your Compose dependency