'How to remove default padding from ExpansionTile's header

By default we have 16 horizontal paddings in ExpansionTile's header, because it is ListTile and it has

/// If null, `EdgeInsets.symmetric(horizontal: 16.0)` is used.
    final EdgeInsetsGeometry contentPadding;

So we have spaces on left and right enter image description here

How to remove them?



Solution 1:[1]

ListTile is styled with ListTileTheme and we can add own styles for child ListTile like this

ListTileTheme(
            contentPadding: EdgeInsets.all(0),
            child: ExpansionTile(...)
)

Solution 2:[2]

The chosen answer is not working fully. In order to get it right you should go :

ListTileTheme(
   contentPadding: EdgeInsets.all(0),
   dense: true,
   horizontalTitleGap: 0.0,
   minLeadingWidth: 0,
   child: ExpansionTile(...)
)

Solution 3:[3]

To customize the Expansion tile widget without much padding and spacing you can do the following changes

ListTileTheme(
        contentPadding: EdgeInsets.all(0),
        dense: true //removes additional space vertically
        child: ExpansionTile(...))

If the trailing space needs to be removed, you can use the modified Expansiontile widget as mentioned in https://stackoverflow.com/a/64162389/12661107 .

Solution 4:[4]

ExpansionTile has tilePadding property, that you can set to

tilePadding: EdgeInsets.only(left: 0)

Solution 5:[5]

Seems it isn't possible with current Flutter version (1.20.3).

A feature was proposed but closed: https://github.com/flutter/flutter/issues/57577

So two options possible now:

Solution 6:[6]

I achieve this by adding horizontaGap -ve value

ListTileTheme( dense: true, horizontalTitleGap: -8.0, minLeadingWidth: 0, child: ExpansionTile(...)

You can adjust for your preferece gap

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kirill Matrosov
Solution 2 Hallel
Solution 3 Dharaneshvar
Solution 4 Artemy
Solution 5
Solution 6 Eng Mghase