Home > Back-end >  Flutter How To Size Horizontal Scrollable In Vertical Layout
Flutter How To Size Horizontal Scrollable In Vertical Layout

Time:04-24

I'm having trouble working out how to size a horizontal scrollable (ListView) within a vertical layout (a vertical ListView in this case).

I want the ListView to be as tall as its contents but am unsure how to achieve this with a horizontal scrollable.

For example:

ListView(
    children: [
        //How do I size this ListView to the height of its child?
        ListView(
            scrollDirection: Axis.horizontal,
            children: [for (int i = 0; i < 2; i  ) Widget()],
        ),
    ],
),

CodePudding user response:

I don't think that would be possible. It would require the ListView to build every child to use the maximum height and this would go again the lazy loading behaviour of the ListView.

CodePudding user response:

Try wrapping the inner ListView with a Container of height: double.infinity

You could wrap the outer ListView in a Container with a height you would like to set, this would set the height of the outer ListView and the inner ListView inside the container should expand this outer ListView's height.

CodePudding user response:

Try using shrinkWrap: true. It's explained in details in official docs and in another answer on stackoverflow

  • Related