Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to place a listview inside a SingleChildScrollView but prevent them from scrolling separately?

Tags:

flutter

dart

I have a widget tree like this:

SingleChildScrollView    Column      Container        ListView(or GridView) 

the problem is that when my widget tree is like above, it gives me error of

NEEDS PAINT

so I change my widget tree like this:

Column      Container        ListView(or GridView) 

but in this situation the ListView or GridView part scrolls separately, and I want the whole widget tree to scroll. how do you think I can achieve it?

like image 455
geekymano Avatar asked May 14 '19 13:05

geekymano


People also ask

How do you make a list view non scrollable?

I found a very simple solution for this. Just get the adapter of the listview and calculate its size when all items are shown. The advantage is that this solution also works inside a ScrollView. Please note to call this function after you have set the adapter to the listview.

What is the difference between ListView and SingleChildScrollView?

For example: You need to only show a list of contacts on your screen and the list items are more or less similar (UI wise and category wise). Then you would use a Listview. A SingleChildScrollView can be compared to "ScrollView" in Android.


1 Answers

You could use your first widget-tree and apply the following changes:

  1. In every ListView and GridView set shrinkWrap: true. This fixes the error message you were getting.
  2. In every ListView and GridView set physics: NeverScrollableScrollPhysics(). This disables the scroll on them and new you can only scroll on the SingleChildScrollView
like image 83
Zvi Karp Avatar answered Sep 22 '22 03:09

Zvi Karp