【问题标题】:How to remove the content padding that the list tile comes with by default?如何删除列表磁贴默认附带的内容填充?
【发布时间】:2018-12-21 14:23:21
【问题描述】:

我正在使用一个带有瓷砖列表的抽屉。每个单独的图块后面都有一个图像和一个文本。所以我把上面提到的小部件排成一排。令我惊讶的是,我发现文本和标题之间有一些无法解释的填充。我附上了一个图块的屏幕截图以便更好地理解:

欢迎提出任何建议!谢谢!。

我添加了rowChildren,这是一个小部件列表,因为我的列表磁贴标题可能包含文本和一些图像:

child = new Container(
  child: new Column(
    children: <Widget>[
      new ListTile(
        dense: true,
        leading: new Image.asset(
                leading,
                color: Colors.white,
              )
        title: new Row(
          children: rowChildren,
        ),
      )
    ],
  ),
);

这是与我分享的图像对应的颤振检查器屏幕截图:

我添加了debugPaintSizeEnabled=true 并得到了这个:

【问题讨论】:

  • 能否提供代码示例?
  • @CliffBrown- 我刚刚添加了。
  • ListTile 中有一个contentPadding 类。目前还不清楚您在屏幕截图上的填充是什么意思。请提供一份能准确表达您的意思的内容。
  • @Bostrot 很抱歉给您带来不便,我问的填充是图像和文本之间的填充。
  • 根据代码和示例,填充比我预期的要高得多。我怀疑该图像的某些内容导致了问题。在您的应用程序 main() 函数中添加 debugPaintSizeEnabled=true; 并在 IntelliJ 或 Android Studio 中重新启动您的应用程序。它将启用调试绘制模式,使填充更清晰。

标签: flutter flutter-layout flutter-dependencies


【解决方案1】:

如何使用 contentPadding

ListTile(
             contentPadding:EdgeInsets.all(0),
             dense: true,
             leading: new Image.asset(
              leading,
              color: Colors.white,
             ),
             title: new Row(
              children: rowChildren,
             ),
            ),

【讨论】:

    【解决方案2】:

    我修好了!!!。解决方法是,不要在主属性中给出主图,而是将它添加到同一行中的孩子。差距消失了!

    List<Widget> rowChildren = [];
    
    rowChildren.add(
        PaddingUtils.embedInPadding(
            new Image.asset(
              $imagePath,
            ),
            new EdgeInsets.only(right: 8.0)),
      );
    

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 2022-08-24
      • 2020-06-11
      相关资源
      最近更新 更多