Mohammed Ali
Mohammed Ali

Reputation: 1185

Modifying the default ExpansionTile children vertical padding Flutter

How can I reduce the vertical padding between the ExpansionTile children:


enter image description here

Here is the inline widget code:

Expanded(
    child: ListView(
        padding: EdgeInsets.all(0.0) ,
        primary: true,
        shrinkWrap: true,
        children: <Widget>[
            ExpansionTile(
                title: Text("Categories"),
                children: [
                    CheckboxListTile(
                        controlAffinity: ListTileControlAffinity.trailing,
                        title: Text( "Cars", maxLines: 1, ),
                      ),
                    CheckboxListTile(
                        controlAffinity: ListTileControlAffinity.trailing,
                        title: Text("Veichle", maxLines: 1, ),
                      ),
                    ],
                initiallyExpanded: true,
                ),
        ],
    ),
),

Upvotes: 4

Views: 3179

Answers (1)

Aspirin_xap
Aspirin_xap

Reputation: 218

By adding A ListTileTheme before each ExpansionTile and making dense: true,
it will make Padding more "Reasonable"

Expanded(
    child: ListView(
        padding: EdgeInsets.all(0.0) ,
        primary: true,
        shrinkWrap: true,
        children: <Widget>[
           ListTileTheme(
           dense: true,
           child: ExpansionTile(
                title: Text("Categories"),
                children: [
                    CheckboxListTile(
                        controlAffinity: ListTileControlAffinity.trailing,
                        title: Text( "Cars", maxLines: 1, ),
                      ),
                    CheckboxListTile(
                        controlAffinity: ListTileControlAffinity.trailing,
                        title: Text("Veichle", maxLines: 1, ),
                      ),
                    ],
                initiallyExpanded: true,
                ),
          ),
        ],
    ),
)

Upvotes: 5

Related Questions