Intermediate
Wrap: Automatically Moving Widgets That Don't Fit to the Next Line
· 6 min read

What Is Wrap?
A Row lays out its children in a single line. When the total width doesn't fit on the screen, it has no option to move to the next line. The result is the yellow-and-black striped overflow warning on the right edge. For tag lists, filter chips or button groups with a variable count, this is unacceptable, because you can't know in advance how many items there will be or how wide the screen will be.
Wrap places its children side by side like a Row. But when there is no room left in the line, it moves the next child to a new line (a run). This way, the same code looks right on a narrow phone screen and in a wide desktop window.

Basic Usage
Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (final tag in tags) Chip(label: Text(tag)),
],
)spacing sets the horizontal gap between items in the same line, and runSpacing sets the vertical gap between lines. In a Row you would have to put a SizedBox between each item; Wrap manages these gaps itself.
Parameters
• direction: The main axis. Defaults to Axis.horizontal. With Axis.vertical, items are laid out top to bottom and move to the next column when the column is full. • spacing: The gap between items along the main axis. Defaults to 0. • runSpacing: The gap between lines (runs). Defaults to 0. • alignment: How the items in each line are distributed along the main axis. Defaults to WrapAlignment.start. • runAlignment: How the lines are distributed when the Wrap has extra space along the cross axis. • crossAxisAlignment: How items of different heights are aligned within their own line. Defaults to WrapCrossAlignment.start. • textDirection, verticalDirection: The layout direction. In right-to-left languages, textDirection is taken into account automatically. • clipBehavior: Defaults to Clip.none.
Alignment: alignment
alignment determines how the free space inside each line is shared. WrapAlignment has the values start, end, center, spaceBetween, spaceAround and spaceEvenly:

Be careful with spaceBetween: the rule is applied to each line separately. If only a few items are left in the last line, they are spread to both ends and the middle of that line. If you don't want that look, start or center gives a more natural result.
Items of Different Heights: crossAxisAlignment
If a line contains items of different heights, such as an avatar, text and a chip, the default start alignment pins them all to the top of the line. Use WrapCrossAlignment.center to center them vertically:
Wrap(
spacing: 12,
runSpacing: 12,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
const CircleAvatar(radius: 24, child: Icon(Icons.person)),
Text('Muhammet Hasan', style: Theme.of(context).textTheme.titleMedium),
const Chip(label: Text('Flutter')),
],
)A Real Example: Filter Chips
class TagFilter extends StatefulWidget {
const TagFilter({super.key, required this.tags});
final List<String> tags;
@override
State<TagFilter> createState() => _TagFilterState();
}
class _TagFilterState extends State<TagFilter> {
final Set<String> _selected = {};
@override
Widget build(BuildContext context) {
return Wrap(
spacing: 8,
runSpacing: 4,
children: [
for (final tag in widget.tags)
FilterChip(
label: Text(tag),
selected: _selected.contains(tag),
onSelected: (isSelected) {
setState(() {
if (isSelected) {
_selected.add(tag);
} else {
_selected.remove(tag);
}
});
},
),
],
);
}
}No matter how many tags there are, the chips are distributed into lines according to the available width. Since the selection is kept in a Set, each chip can be toggled independently.
Things to Watch Out For
1. Wrap Needs to Know the Width
Wrap decides when to move to the next line by looking at the maximum width. Inside a parent that gives unbounded width, such as a Row, all items stay on a single line and no wrapping happens:
// Doesn't wrap: Row gives Wrap unbounded width
Row(
children: [
const Icon(Icons.label),
Wrap(spacing: 8, children: chips),
],
)
// Correct: Expanded bounds the width
Row(
children: [
const Icon(Icons.label),
Expanded(child: Wrap(spacing: 8, children: chips)),
],
)2. Expanded and Flexible Can't Be Used
Expanded and Flexible only work inside Row, Column and Flex. If you use them as children of a Wrap, you get an "Incorrect use of ParentDataWidget" error. If you want items to fill the line with equal widths, a GridView or calculating widths with LayoutBuilder is a better fit.
3. Use a Lazy List for Many Items
Wrap builds and lays out all of its children at once, including items that aren't visible on screen. That's fine for dozens of tags, but for hundreds or thousands of items, prefer widgets that only build visible items, such as GridView.builder or SliverGrid.
Wrap, Row or GridView?
• The number of items is fixed and they definitely fit in one line: Row. Since Flutter 3.27, Row and Column also support the spacing parameter. • The number or widths of items vary and they should keep their natural widths: Wrap. • The items should form an equally sized grid, or there are a lot of them: GridView.
Conclusion
Wrap is one of the simplest building blocks of responsive interfaces. Instead of fighting overflow warnings, it lets items find their own lines. Manage gaps with spacing and runSpacing, and alignment with alignment and crossAxisAlignment. Remember that Wrap needs a bounded width and isn't suited to large lists.