Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : make two listviews scrollable as one

Tags:

flutter

dart

I'm trying to make a screen that's scrollable (like the whole screen scrollable).

This is what I got know:

Column(
          children: <Widget>[

                 Expanded(
                    child: ListView(
                        scrollDirection: Axis.horizontal, children: posts2b)),

            Expanded(child: ListView(children: posts2a)),
          ],
        );

It all works, but I want those listviews scrollable as one. So if you scroll down, the horizontal listview 'disappears'.

Is that possible?

Thank you!

like image 432
Karel Debedts Avatar asked Jul 12 '26 15:07

Karel Debedts


2 Answers

Something like this?

SingleChildScrollView(
  child: Column(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      SizedBox(
        height: 200,
        child: ListView(
          scrollDirection: Axis.horizontal,
          children: posts2b,
        ),
      ),
      Flexible(
        child: ListView(
          physics: NeverScrollableScrollPhysics(),
          shrinkWrap: true,
          children: posts2a,
        ),
      ),
    ],
  ),
)

Wrap Column with SingleChildScrollView, set height for horizontal list and disable scrolling for vertical list by adding physics: NeverScrollableScrollPhysics() ...

like image 113
janstol Avatar answered Jul 15 '26 05:07

janstol


Use SizedBox() and give the option, shrinkWrap: true.

SizedBox(
              child: ListView(
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
...
),
SizedBox(
              child: ListView(
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
...
),
like image 37
dongwoo Avatar answered Jul 15 '26 05:07

dongwoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!