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?
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.
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.
You could use your first widget-tree and apply the following changes:
ListView
and GridView
set shrinkWrap: true
. This fixes the error message you were getting.ListView
and GridView
set physics: NeverScrollableScrollPhysics()
. This disables the scroll on them and new you can only scroll on the SingleChildScrollView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With