kakyo
kakyo

Reputation: 11640

flutter: listview blank divider

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?

Upvotes: 2

Views: 732

Answers (1)

dhanasekar
dhanasekar

Reputation: 1333

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'),
    );
  },
)

Upvotes: 3

Related Questions