I have a ListView.builder
that uses shrinkWrap
because I get an error if I don’t use it.
As a result of this answer, there will be a lot of white space above ListView.builder
:
How can I remove it?
My code:
SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Summary",
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
…
],
),
ListView.builder(
shrinkWrap: true,
cacheExtent: 9999,
itemCount: list.length,
itemBuilder: (context, index) => ListTile(…),
),
],
),
),
Feel free to leave a comment if you need more information.
How can I change the position of the ListView.builder
that uses shrinkWrap
?
2
Answers
Instead of using
ListView.builder
, you should useColumn
:I don’t know by "space above
ListView.builder
" or "How can I change the position of theListView.builder
that usesshrinkWrap
?" what you meanPossible solutions considering all cases:
If it’s outside the
ListView
is because of wrapping it inCenter
which is obvious.If you are referring to the top margin inside the
ListView
it is because of this linemargin: EdgeInsets.all(32),
You just have to remove
Center
widget, it will change it’s position to the start of the app.Extra: You can remove the default
padding
ofListView.builder
by addingpadding:EdgeInsets.zero
. If this is what you are talking about.Note: You dont have to use
shrinkWrap:true
everytime , it is preferred to be used, only when yourlistView
is inside anotherScrollable
view. Else it is preferred to befalse
which is the option by defaultRefer the docs: