When building layouts in Flutter, you often need to place items side-by-side.
Arranging Widgets
Flutter provides several ways to do this. Two useful widgets are OverflowBar
and Wrap
. They seem similar because they arrange their children, but they handle limited space differently.
What is OverflowBar?
The OverflowBar
tries to keep all its children in a single line, usually horizontally. If there isn't enough space, the children will extend beyond the available area.
This is useful when you want to make sure your items are always on one line, even if it means they might not all be visible without scrolling (in a scrollable parent).
What is Wrap?
The Wrap
widget also places children next to each other. However, if there isn't enough space on the current line, it will automatically move the next child to a new line.
Think of it like text wrapping in a paragraph. This is great for creating layouts that adjust nicely to different screen sizes or orientations.
The Key Difference
In simple terms:
OverflowBar
Forces children onto one line, even if they overflow.
Wrap
Wraps children onto a new line if space runs out.
Looking at the image examples, the phone in landscape mode clearly shows the effect: OverflowBar keeps the two items on one line (even if the blue one is cut off), while Wrap moves the red item to the next line because there isn't enough width.