How to simulate spaceBetween behavior in a listView?

56 Views Asked by At

I have a Column of items like this:

Column(
  children: [
    ...items,
    Spacer(),
    Footer(),
  ],
)

However, the items list may be dynamic, which makes necessary use a ListView instead of Column. The only problem is that my Footer was separated with anSpacer, the Spacer widget will throw error if its used in a ListView.

What can I use to give the effect of a Column to my ListView when are just a few items that not filled all the screen?

3

There are 3 best solutions below

2
On

I found this solution:

CustomScrollView(
  slivers: <Widget>[
    SliverList(
      delegate: SliverChildListDelegate(items),
    ),
    SliverFillRemaining(
      hasScrollBody: false,
      child: Footer(),
    ),
  ],
),
0
On

You can use SizeBox(heigth:your hieght) instead of Spacer();

0
On

This is the issue I had a lot when I was still learning.

I think you have a same issue,

Step 1: You shouldn't use SingleChildScrollView as a parent of that Column.

Step 2: Use Expanded Widget inside the Column.

Step 3: Inside the Expanded use another Column and put those items.

For example:

Column(
  children: [
    Expanded(
      child: Column(
       children: [
         ...items,
      ],
    ),
    Footer(),
  ],
)

You can have the scroll behaviour for that 2nd Column by giving SingleChildScrollView or use any ListView