74

I need to remove some padding between leading Widget and title Widget in a ListTile. It has too much blank spaces. Is there a way to do that? The code that I am using for that is this:

ListTile _getActionMenu(String text, IconData icon, Function() onTap) {
  return new ListTile(
    leading: new Icon(icon),
    title: new Text(text),
    onTap: onTap,
  );
}
Joseph Arriaza
  • 12,014
  • 21
  • 44
  • 63
  • Does this answer your question? [How to reduce the margin between 'leading' and 'title' for ListTile ? Flutter](https://stackoverflow.com/questions/53474168/how-to-reduce-the-margin-between-leading-and-title-for-listtile-flutter) – iDecode Jan 24 '21 at 20:55
  • With the release of Flutter 2.0.0, it would appear [@Dinesh-Bala's answer](https://stackoverflow.com/a/65411554/638153) would be worthy consideration for this question. – Keith DC Mar 04 '21 at 01:52

18 Answers18

84

You can use the minLeadingWidth on your ListTile. The default value is 40, so you can use a lower value to make your leading and title come closer.

ListTile(
  leading : Icon(Icons.settings),
  title : Text("Settings"),
  minLeadingWidth : 10,
);
Dinesh Bala
  • 947
  • 7
  • 8
  • 1
    This will be awesome when it's in the Stable channel. As of 2021-03-02 it's in Dev channel. The [edited file's GitHub branch tag](https://github.com/flutter/flutter/commit/8cb266511897d79e6d7d60c08c0e425f4cdaf433#diff-c4ef7c798c820ecda6cab38be1c2d619d5349dc478889f3a54ebbe07f60c11f2) is `1.27.0-8.0.pre` (Stable is [currently at 1.22.6](https://flutter.dev/docs/development/tools/sdk/releases)). – Keith DC Mar 03 '21 at 08:01
  • 2
    It's one day later and [`flutter upgrade` just upgraded to `2.0.0`](https://flutter.dev/docs/development/tools/sdk/releases). If I'm reading it right, it would appear this included all Dev (and Beta) channel changes (Dev now has a newer `2.1.0-10.0.pre` build). I'm still on the Stable channel and this option **`minLeadingWidth` is now available**. – Keith DC Mar 04 '21 at 01:46
  • for some reason it doesn't work inside a popup menu, The increment is reflected but not the decrement – xrayian Dec 20 '21 at 08:30
69

EDIT: After Flutter 2.0 upgrade

As Dinesh has pointed out here, ListTile has received a minLeadingWidth property.

Default value is 40, so to reduce space between leading and title by x pass minLeadingWidth: 40 - x.


Align results will depend on text and tile width.

Use Transform.translate for consistent results.

ListTile(
  leading: Icon(icon),
  title: Transform.translate(
    offset: Offset(-16, 0),
    child: Text('Some text'),
  ),
);
Rustem Kakimov
  • 2,421
  • 20
  • 25
48

You can use Align and specify the Alignment.

ListTile _getActionMenu(String text, IconData icon, Function() onTap) {
  return new ListTile(
    leading: new Icon(icon),
    title: Align(
      child: new Text(text),
      alignment: Alignment(-1.2, 0),
    ),
    onTap: onTap,
  );
}
westdabestdb
  • 4,353
  • 20
  • 28
  • 11
    titles became assymetric – temirbek Apr 02 '19 at 03:34
  • 1
    Your solution works but not if I put the Text in a container. I put it in a container because I want to set a background color, but then the Align stops doing anything. Does anyone know a workaround please? – Texv May 05 '20 at 14:33
  • If the implementation of list tile changes this will cause issues. (e.g the default padding changes in list tile) A better approach is to not use leading and add the required leading widget as part of the title using a row widget. Shown in other answers here. – Lee Higgins Nov 02 '20 at 12:52
36

For those who are looking for a clean, one line answer now. You can use

ListTile(
 horizontalTitleGap: desiredDoubleValue,
);
Marc Sanny
  • 816
  • 6
  • 12
  • 4
    Why this answer isn't more up-voted ? Works like a charm along with `minLeadingWidth`. – gruvw Jun 30 '22 at 16:43
32

this code is the solution

...
    contentPadding:EdgeInsets.all(0),
...
Alex Haslam
  • 3,269
  • 1
  • 13
  • 20
Mehrdad
  • 1,477
  • 15
  • 17
16

An ugly workaround I've found for this is to put a Row widget in the title section and then put the icon and the text inside that Row with a SizedBox in the middle. This way you can control how much space you want between them:

ListView(
  shrinkWrap: true,
  children: <Widget>[
    ListTile(
      title: Row(
        children: <Widget>[
          Icon(Icons.android),
          SizedBox(
            width: 5, // here put the desired space between the icon and the text
          ),
          Text("Title") // here we could use a column widget if we want to add a subtitle
        ],
      ),
    )
  ],
)

enter image description here

Juan Carlos Mendoza
  • 5,736
  • 7
  • 25
  • 50
  • 8
    This is not that ugly, less than the accepted answer IMO. At least you can exactly control the padding and it is not dependant on the device aspect ratio. – ncuillery Aug 07 '20 at 20:24
  • I'm a novice, but I agree with @ncuillery - this is a fine solution. Thanks! – Mark Gavagan Nov 23 '20 at 20:39
  • I'm not 100% sure but I believe there's gonna be a phantom padding between the null leading and the title of the tile still. – Csaba Toth Dec 18 '20 at 22:32
8

I have the same problem these days, and finally I published one package which may can solve this problem.

The package is available at https://pub.dev/packages/list_tile_more_customizable, and with this package we can set the horizontalTitleGap, and when it has been set to 0.0(zero), the padding between leading and title will become zero.

Usage:

ListTileMoreCustomizable(
    title: Text("Title"),
    trailing: Icon(Icons.people),
    horizontalTitleGap: 0.0,
    onTap: (details){},
    onLongPress: (details){},
);

Edited:
This method works great for me, and also the code is available at https://github.com/Playhi/list_tile_more_customizable (the raw code is too long) under BSD License, I'm hard to understand why one user down-voted the answer without submitting any problems on it.

Playhi
  • 137
  • 1
  • 4
  • 3
    If you rename your package to BetterListTile probably you get upvote :P – devnomic Mar 11 '20 at 09:43
  • 2
    It seems as if these modifications are already merged into Flutter master channel: https://github.com/flutter/flutter/pull/64222 – RobDil Feb 03 '21 at 13:13
6

set horizontalTitleGap to 0

 ListTile(
                          contentPadding: EdgeInsets.zero,
                          minLeadingWidth: 5,
                          ***horizontalTitleGap: 0,***
                          leading: widget,
                          title: widget ,
                         )
Cora Bica
  • 79
  • 2
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '22 at 06:20
5

Use horizontalTileGap:

ListTile(
        horizontalTitleGap: 0,
        leading: CircleAvatar(
          radius: 50,
          backgroundImage:
              NetworkImage("https://picsum.photos/250?image=1"),
        ),
        title: Text("Image 6"),
      ),
Malik Zaib
  • 81
  • 1
  • 9
3

Instead, you can create your own Widget as below:

  1. Let's say we'll create a widget file called text_icon.dart
    import 'package:flutter/material.dart';

      class TextIcon extends StatelessWidget {
        final String title;
        final IconData icon;
        final String button;

        const TextIcon({Key key, this.title, this.icon, this.button}) : super(key: key);

        @override
        Widget build(BuildContext context) {
          final theme = Theme.of(context);

          return Padding(
            padding: const EdgeInsets.only(bottom: 24.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Icon(
                 icon,
                 size: 18,
                ),
               SizedBox(width: 5),
               Text(
                 title,
                 style: theme.textTheme.subhead.copyWith(fontSize: 13),
               ),
             ],
           ),
         );
       }
     }
  1. Call your widget in your screen

    TextIcon(icon: Icons.pause_circle_filled, title: "John Doe")
    
d3vma
  • 161
  • 2
  • 10
3

Now ListTile has the property of minLeadingWidth.

Example

ListTile(
      minLeadingWidth: 15,
      leading: Icons(Icons.search),
      title: Text("Data");
moin khan
  • 51
  • 5
2

It can be solved by simply adding: contentPadding: EdgeInsets.zero,

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
A.K.J.94
  • 492
  • 6
  • 14
2

You must to add this parameter.

return ListTile(
    leading: new Icon(icon),
    title: new Text(text),
    onTap: onTap,
    //Add this parameter
    contentPadding: EdgeInsets.zero,
);
1

I think a ListTile is not the correct widget a more elegant approach would be:

FlatButton.icon(
    onPressed: null,
    icon: Icon(
      Icons.flag_rounded,
      color: Colors.white,
    ),
    label: Text('Title'))
Hlulani
  • 419
  • 4
  • 12
1

This code is enough to adjust the gap between the title and leading

horizontalTitleGap: 1
Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
0

This one works for me. Keep the minLeadingWidth as 0, and adjust the horizontalTitleGap to acheive the desired output.

return ListTile(
    leading: new Icon(icon),
    title: new Text(text),
    horizontalTitleGap: 8,
    minLeadingWidth: 0,
);
Guhan
  • 35
  • 6
0
ListTile(
        contentPadding: EdgeInsets.zero,  // Remove padding before leading icon
        horizontalTitleGap: -14.0,  // Reduce padding between title and leading icon 
      ),
Omar
  • 456
  • 7
  • 7
  • Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Aug 26 '23 at 00:04
-1

horizontalTitleGap: value, minLeadingWidth: value, use the two together. Works pefectly. the values have to be the same.