skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    I found this solution:

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

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

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search