修改默认的 ExpansionTile 子女垂直填充 Flutter

问题描述 投票:1回答:1

如何减少ExpansionTile子代之间的垂直填充。 enter image description here

这里是内联小组件代码。

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,
                ),
        ],
    ),
),
flutter widget flutter-layout
1个回答
1
投票

通过添加A ListTileTheme 前每 ExpansionTile 并使 dense: true, 它将使Padding更多 "合理"

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,
                ),
          ),
        ],
    ),
)
© www.soinside.com 2019 - 2024. All rights reserved.