Flutter | How to add a SizedBox() as the last item of a ListView.builder()?

Viewed 674

I'm trying to put some space or a SizedBox() as the last item of the ListView, because the FloatingActionButton() is hiding some information from the last ListTile.

I want to scroll to the space/SizeBox() like WhatsApp for example.

body: ListView.builder(
    itemCount: cardsList.length,
    itemBuilder: (context, i) {
      return Column(
        children: [
          ListTile( ... ),
          Divider( ... ),
        ],
      );
    },
  ),
3 Answers

ListView has padding property

body: ListView.builder(
    padding: const EdgeInsets.only(bottom: 100),
    itemCount: cardsList.length,
    itemBuilder: (context, i) {
      return Column(
        children: [
          ListTile( ... ),
          Divider( ... ),
        ],
      );
    },
  ),

You can wrap your ListView with the Column widget. In that widget add the SizedBox. Like this:

body: Column(
  children: [
    ListView.builder(
      itemCount: cardsList.length,
      itemBuilder: (context, i) {
        return Column(
          children: [
            ListTile( ... ),
            Divider( ... ),
          ],
        );
      },
    ),
    SizedBox(height: 50.0)
  ]
)

I think you want this

 ListView.builder(
        itemCount: cardsList.length + 1,
        itemBuilder: (context, index) =>
            index < items.length ? myListTile() : SizedBox(),
      ),
Related