Represents a configuration for a flex item within a FlexBox.

This configuration is defined via a lambda that operates on a FlexConfigScope. Because this configuration block is executed during the layout phase rather than the composition phase, reading state variables inside the block will only trigger a layout pass, completely avoiding costly recompositions.

Configuration properties are applied sequentially. If a property (such as grow or shrink) is assigned multiple times within the configuration block, the final call takes precedence.

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.FlexAlignSelf
import androidx.compose.foundation.layout.FlexBox
import androidx.compose.foundation.layout.FlexConfig
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// Define reusable FlexConfig - can be a top-level constant
val FlexibleCentered = FlexConfig {
    grow(1f)
    shrink(0f)
    basis(100.dp)
    alignSelf(FlexAlignSelf.Center)
}

FlexBox(modifier = Modifier.fillMaxWidth().height(100.dp)) {
    Box(Modifier.background(Color.Blue).flex(FlexibleCentered))
}

Summary

Public functions

Unit

Applies the configuration to the given FlexConfigScope.This method is invoked by the layout system during the measurement phase, not during composition.

Cmn

Public functions

FlexConfigScope.configure

fun FlexConfigScope.configure(): Unit

Applies the configuration to the given FlexConfigScope.This method is invoked by the layout system during the measurement phase, not during composition.