ifTrue

inline fun Modifier.ifTrue(predicate: Boolean, builder: Modifier.() -> Modifier): Modifier

Modifier to make it easy to conditionally add a modifier based on predicate

Box(
modifier = Modifier.fillMaxWidth()
.ifTrue(isError) { background(SparkTheme.colors.error) }
.padding(16.dp)
) {...}

Parameters

predicate

condition to decide if the builder is added or not to the modifier chain

builder

the modifier(s) to apply when predicate is true