Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

Flutter. How to make row items go to new line of width not enough?

  1. User

    Flutter. How to make row items go to new line of width not enough?

  2. Assistant

    To make row items in Flutter go to a new line if the width is not enough, you can use the Wrap widget instead of the Row widget.

    The Wrap widget takes a list of children and lays them out in a horizontal or vertical line, similar to the Row or Column widget. 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.