Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use divideTiles() in Flutter?

Tags:

flutter

I am trying to build a ListView with dividers between each ListTile. I saw that there is a static method to do that called divideTiles() but i did not understand how to use that.. How/where is this function used?

My code is a simple ListView with ListTiles as children.

like image 770
Daniel Vilela Avatar asked Sep 06 '18 15:09

Daniel Vilela


People also ask

How do you add a separator in Flutter?

If you have a list of widgets, you may need to add a separator between the widgets. In Flutter, there are two widgets suitable for that purpose: Divider and VerticalDivider . Divider is used to create a horizontal line divider, while VerticalDivider is used to create a vertical line divider.

How do you give bottom border to ListTile in Flutter?

To add ListTile bottom or top border, you can wrap the ListTile widget inside the Container and add the decoration. Inside the decoration parameter, add the Boxdecoration widget with border parameter and assign it to either Border(bottom: new BorderSide()) or Border(bottom: new BorderSide()).

How do I use ListView separated in Flutter?

separated. In Flutter, you can use ListView. separated to easily create a list view whose items are separated by separators (or dividers). A separator only appears between two list items and never stands before the first or sits after the last item.


1 Answers

ListView(
  children: ListTile.divideTiles(
    context: context,
    tiles: [
      // your widgets here
    ]
  ).toList(),
)

Alternatively you can go with ListView.separated:

ListView.separated(
  itemCount: 42,
  itemBuilder: (context, index) {
    // your widget here 
  },
  separatorBuilder: (context, index) {
    return Divider(); 
  },
);
like image 74
Rémi Rousselet Avatar answered Oct 01 '22 16:10

Rémi Rousselet