androidx.compose.foundation.layout

FlexBoxSince 1.11Experimental

Composable function · from org.jetbrains.compose.foundation:foundation-layout:1.12.2

FlexBox lays out children in one direction and wraps them onto new lines, like FlowRow. In addition, each child can grow to fill free space or shrink when space is short, like CSS Flexbox. It can do everything Row, Column and the flow layouts do.

It is new and experimental: add @OptIn(ExperimentalFlexBoxApi::class). Its API may still change.

FlexBox(
    config = FlexBoxConfig {
        direction(FlexDirection.Row)
        wrap(FlexWrap.Wrap)
        gap(8.dp)
    },
) {
    Text("Grows", Modifier.flex { grow(1f) })
    Text("Fixed")
    Text("Shrinks first", Modifier.flex { shrink(2f) })
}

If a Row with Modifier.weight or a FlowRow does what you need, use those. They are stable.

Read more

ParametersExperimental

@Composable
fun FlexBox(
    modifier: Modifier = Modifier,
    config: FlexBoxConfig = FlexBoxConfig,
    content: @Composable FlexBoxScope.() -> Unit,
)

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

config: FlexBoxConfigOptional

Default: FlexBoxConfig

Direction, wrapping, alignment and gaps of the container. Create it with FlexBoxConfig { ... }.

content: @Composable FlexBoxScope.() -> UnitRequired

The children. Each can use Modifier.flex { } to grow, shrink or align itself.