flutter: listview blank divider

344

you can use ListView.separated

ListView.separated(
  itemCount: 25,
  separatorBuilder: (BuildContext context, int index) => SizedBox ( height : <height>),
  itemBuilder: (BuildContext context, int index) {
    return ListTile(
      title: Text('item $index'),
    );
  },
)
Share:
344
kakyo
Author by

kakyo

Updated on December 22, 2022

Comments

  • kakyo
    kakyo 2 minutes

    Goal

    I'd love to have a ListView where there are 4 ListTiles and a divider right before its last ListTile, but I don't want the horizontal line with the Divider, only a blank space with customizable height.

    Problem

    So far I haven't found a straightforward way other than inserting an empty container before the last two tiles.

    The thing is: I have a model List behind the ListView. I'd love to match the selected items in the list to the ListView. So there had better be a 1-to-1 mapping between data and view. This makes it convenient to configure the looks for selecting the ListTiles. Having a non-data divider in the view skews the mapping, i.e., now I'd have 4 data items, but 5 items in the view. So I couldn't just use

    child: ListTile(
      selected: model[i].isSelected,
    )
    

    Question

    Am I asking for too much from the ListView or is there a straightforward way to achieve what I want?

    • Shubham Gupta over 2 years
      Did you check ListView.separated?