如何在Flutter ListTile中设置开头和标题之间的填充? [英] How to set the padding between leading and title from Flutter ListTile?

查看:196
本文介绍了如何在Flutter ListTile中设置开头和标题之间的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个妥协的解决方案,在这个解决方案之下,我不满意.

i have a compromise solution below which do not satisfy me .

final int padding=10; //the padding you wanna set.
ListTile(
    leading: Icon(icon),
    title:  Container(
                  height: 30,
                  child: Stack(
                    alignment: Alignment.centerLeft,
                    overflow: Overflow.visible,
                    children: <Widget>[
                      Positioned(
                        child: title,
                        left: padding-35,
                      ),
                    ],
                  ),
                ),
 );

是的.您可以使用负边距.这肯定有效.但这不是完美的.那么有人可以提供更好的解决方案吗?

yes. you can use the negative margin. which definitely works. but it is not perfect .so could anyone offer a better solution ?

==========附加==========

========= Additional ===========

我在下面看到了一些答案.但是看来您没有理解我的观点.

i see some answer below .but it seems you do not get my points.

Flutter ListTile中开头和标题之间的默认填充对于我来说太大了.我想自己调整填充物.仅用Padding小部件包装标题无法实现目标.

the default padding between leading and title from Flutter ListTile is too large for me. i wanna adjust the padding by myself . and just wrapping the title with Padding widget can not achieve the goal .

=========我找到了更好的解决方案===========

final int padding = 10; //the padding you wanna set.
ListTile(
  leading: Icon(icon),
  title: Container(
    transform: Matrix4.translationValues(padding - 35, 0.0, 0.0),
    child: title,
  ),
);

推荐答案

您可以为此在标题小部件中添加填充.

You can add padding to your title widget for this.

将代码替换为:

final double padding=10; //the padding you wanna set.
ListTile(
    leading: Icon(icon),
    title: Padding(
             padding: const EdgeInsets.all(padding),
             child:Container(
             height: 30,
             child: Stack(
               alignment: Alignment.centerLeft,
               overflow: Overflow.visible,
               children: <Widget>[
                 Positioned(
                   child: title,
                   left: padding-35,
                 ),
               ],
             ),
           ),
         ),
 );

这篇关于如何在Flutter ListTile中设置开头和标题之间的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆