Search code examples
flutterflutter-web

Flutter consistent spacing for List Tile elements


Inconsistent Spacing

I have a ListView.Builder with ListTiles and I would like the spacing to be consistent across the data fields. The way I have it setup now is by using Spacers in between each element such as this:

return ListTile(
    title: Row(children: [
        Text(data[0]),
        Spacer(),
        Text(data[1]),
        Spacer(),
        Text(data[2])
    ])
);

I'm looking for a solution that will keep the spacing responsive without the spacing being inconsistent across the ListView.builder.


Solution

  • You may have to set a width for the Text

    final size = MediaQuery.of(context).size;
    return ListTile(
        title: Row(children: [
            SizedBox(
            width: size.width/4,
            child: Text(data[0]),
             )
            Spacer(),
            Text(data[1]),
            Spacer(),
            Text(data[2])
        ])
    );