Flutter - How to remove default spacing in ListTile

In flutter, ListTile is a very useful widget, ListTile is a UI element that displays related information. ListTile widget takes some space by default sometimes we might remove that default space then how do we can? We can use VisualDensity or dense properties of ListTile like below.

ListTile(
    dense: true,
    visualDensity: VisualDensity(horizontal: 0, vertical: -4),
);

- How do you remove padding between the leading and the title in ListTile?:

Sometimes also we need to remove extra space between the leading  icon and title in ListTile, We can use minLeadingWidth properties of ListTile.

 ListTile(
            
              title: Text('Errorgram'),
              leading : Icon(Icons.settings),
              trailing: Icon(Icons.more_vert),
              minLeadingWidth : 10,//Change here
            ),

Full Example : 


class Errorgram extends StatefulWidget {
  const Errorgram({Key? key, required this.title}) : super(key: key);
  final String title;
  @override
  State<Errorgram> createState() => _ErrorgramState();
}

class _ErrorgramState extends State<Errorgram> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text("Errorgram",style:TextStyle(color:Colors.black),),
      ),
      body: Container(
        margin: EdgeInsets.only(left: 10,right: 10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ListTile(
              shape: RoundedRectangleBorder(
                side: BorderSide(width: 2),
                borderRadius: BorderRadius.circular(20),
              ),
              title: Text('Errorgram'),
              dense: true,
              visualDensity: VisualDensity(horizontal: 0, vertical: -4),
              trailing: Icon(Icons.more_vert),
              minLeadingWidth : 10,//Change here for remove padding between the leading and the title 
            ),
          ],
        ),
      ),

    );
  }
}

I hope you like this article and it will be help to you.

Tags: