gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
Flutter. How to make row items go to new line of width not enough?
- User
Flutter. How to make row items go to new line of width not enough?
- Assistant
To make row items in Flutter go to a new line if the width is not enough, you can use the
Wrapwidget instead of theRowwidget.The
Wrapwidget takes a list of children and lays them out in a horizontal or vertical line, similar to theRoworColumnwidget. However, if the width is not enough, it automatically starts a new line to accommodate the remaining items.Here's an example:
Wrap( children: [ Container( width: 100, height: 100, color: Colors.red, ), Container( width: 100, height: 100, color: Colors.green, ), Container( width: 100, height: 100, color: Colors.blue, ), Container( width: 100, height: 100, color: Colors.orange, ), Container( width: 100, height: 100, color: Colors.purple, ), ], ),This code will show five containers of 100x100 pixels, laid out horizontally. However, if the width of the screen is not enough to accommodate all five containers, it will automatically start a new line for the remaining items.