A FlowRow That Wraps Chips
Build a real wrapping layout from scratch.
A FlowRow That Wraps Chips is a free Jetpack Compose Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What a Flow Row Does
A flow row places children left to right, then wraps to a new line when it runs out of width. Perfect for tag chips and filters. 🏷️
Start From the Layout Composable
You already know the tool: the Layout composable. The wrapping logic lives entirely in how you measure and place children.
Layout(content, modifier) { measurables, constraints ->
}Measure Children Loosely
Measure each chip with the parent's maxWidth but no minimum, so chips size to their content rather than stretching full width.
val placeables = measurables.map {
it.measure(constraints.copy(minWidth = 0))
}Track the Current Row Width
Walk the placeables and keep a running row width. Each chip you add increases it by the chip's own width.
Wrap When the Row Overflows
If adding the next chip would exceed maxWidth, reset the row width and move down by the tallest chip in the finished row.
if (rowWidth + placeable.width > maxWidth) {
y += rowHeight
rowWidth = 0
}Remember Each Chip's Position
As you scan, store the chosen x and y for every chip in a list. You will replay these positions during the placement step.
Compute the Total Height
After the last row, the layout's height is the final y plus that row's height. The width is simply the constraint's maxWidth.
Report Size and Place Chips
Call layout with your total width and height, then loop through the stored positions, calling placeRelative on each placeable.
layout(maxWidth, totalHeight) {
placeables.forEachIndexed { i, p ->
p.placeRelative(positions[i])
}
}Add Horizontal Spacing
Insert a small gap between chips by adding a spacing value to the row width after each chip. Vertical gaps work the same way.
Compose Ships FlowRow Too
The official FlowRow from the layout library does all this for you. Building it yourself shows exactly how that magic works under the hood. ✨
FlowRow { Chip("Kotlin"); Chip("Compose") }You Built a Real Layout
You measured children, wrapped rows by width, and placed each chip by hand. That is a production-grade custom layout built from first principles. 🎉
Quick Check
What triggers the flow row to start a new line?
Recap: A FlowRow That Wraps Chips
You measured chips loosely, tracked row width, and wrapped to a new line on overflow, then placed each one. That is FlowRow from scratch. ✅
Frequently asked questions
Is the “A FlowRow That Wraps Chips” lesson free?
Yes — the full text of “A FlowRow That Wraps Chips” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.
What will I learn in “A FlowRow That Wraps Chips”?
Build a real wrapping layout from scratch. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Jetpack Compose Academy?
No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “A FlowRow That Wraps Chips” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Jetpack Compose Academy lesson?
Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The Measure & Place Model
- Writing a Layout Composable
- Constraints & Intrinsic Measurements
- A FlowRow That Wraps Chips