Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - List Tiles or Card Separators

I am building a listview from a Firestore Database. I originally wanted to separate my items by ListTiles since I know they can do separators, but I was not getting the height that I wanted out of the tiles, so I moved to transparent Cards.

Problem is I cannot figure out how to add a separator or divider after each card.

Here is my code so far

Widget build(BuildContext context) {
if (snapshot == null) return CircularProgressIndicator();
return Scaffold(
  body: ListView.builder(
          itemCount: snapshot.length,
          itemBuilder: (context, index){
            return Card(
              elevation: 0,
              color: Colors.transparent,
              child: Row(
                children: <Widget>[
                  Padding(padding: EdgeInsets.all(10.0),),
                  Column(
                    children: <Widget>[
                      Padding(padding: EdgeInsets.all(10.0),),
                      Text(snapshot[index].data["month"], style:
                        TextStyle(fontSize: 30, fontWeight: 
FontWeight.w300),),
                      Text(snapshot[index].data["day"], style:
                      TextStyle(fontSize: 20),),
                    ],
                  )
                ],
              ),
            );
          }
        ),
      );

  }
}

Desired enter image description here

Current

enter image description here

I would think list tiles would work better, but I tried what I knew how to do to build custom list tiles and i could not replicate the results.

like image 563
Bnd10706 Avatar asked Nov 16 '25 00:11

Bnd10706


1 Answers

Use ListView.separated

ListView.separated(
  separatorBuilder: (context, index) => Divider(
        color: Colors.black,
      ),
  itemCount: 20,
  itemBuilder: (context, index) => Padding(
        padding: EdgeInsets.all(8.0),
        child: Center(child: Text("Index $index")),
      ),
)

or divideTiles()

ListView(
  children: ListTile.divideTiles(
    context: context,
    tiles: [
      // your widgets here
    ]
  ).toList(),
)
like image 196
Doc Avatar answered Nov 17 '25 19:11

Doc