ifNotNull

inline fun <T : Any> Modifier.ifNotNull(value: T?, builder: Modifier.(T) -> Modifier): Modifier

Modifier to make it easy to conditionally add a modifier based on value nullability

Box(
modifier = Modifier.fillMaxWidth()
.ifNotNull(errorMetadata) { errorData -> background(errorData.color) }
.padding(16.dp)
) {...}

Parameters

value

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

builder

the modifier(s) to apply when value is not null