【问题标题】:How to remove default padding from ExpansionTile's header如何从 ExpansionTile 的标题中删除默认填充
【发布时间】:2019-07-09 22:07:51
【问题描述】:

默认情况下,我们在 ExpansionTile 的 标题中有 16 个水平填充,因为它是 ListTile 并且它有

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

所以我们左右两边都有空格

如何删除它们?

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    所选答案未完全发挥作用。 为了把它做好,你应该去:

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

    【讨论】:

      【解决方案2】:

      ExpansionTile 有 tilePadding 属性,你可以设置为

      tilePadding: EdgeInsets.only(left: 0)
      

      【讨论】:

        【解决方案3】:

        要在没有太多填充和间距的情况下自定义扩展磁贴小部件,您可以进行以下更改

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

        如果需要删除尾随空格,您可以使用 https://stackoverflow.com/a/64162389/12661107 中提到的修改后的 Expansiontile 小部件。

        【讨论】:

          【解决方案4】:

          目前的 Flutter 版本 (1.20.3) 似乎不可能。

          提出了一项功能但已关闭: https://github.com/flutter/flutter/issues/57577

          所以现在有两种选择:

          【讨论】:

          • Flutter 1.20.3+ 可以。确保使用最新的稳定版。这个issue 是关于高度和空间的,而不是关于填充的。不要用错误的答案混淆人们
          【解决方案5】:

          ListTile 使用 ListTileTheme 进行样式设置,我们可以像这样为子 ListTile 添加自己的样式

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

          【讨论】:

          • 它只从左侧删除填充
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-04-23
          • 1970-01-01
          • 2023-02-08
          • 2015-11-11
          • 2021-04-04
          • 1970-01-01
          • 2018-10-17
          相关资源
          最近更新 更多