简体   繁体   English

如何在 Listtile 的前导和尾随之间对齐小部件? - Flutter

[英]How to align a widget between Listtile´s leading and trailing? - Flutter

I would like to set the width of the progress bar equal to the width between Listtile´s leading and trailing but till now, I only can fit it to the entire width of the card.我想将进度条的宽度设置为等于 Listtile 的前导和尾随之间的宽度,但到目前为止,我只能将它设置为卡片的整个宽度。 Do I need padding or something?我需要填充或其他东西吗? This is my code (and screenshot of my view):这是我的代码(和我的观点的截图):

Card(
                  child: Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[ ListTile(
                    leading:  CircleAvatar(
                      backgroundImage:  AssetImage("assets/vegetables/" + activity.cropImgUrl),
                      backgroundColor: Colors.white,
                    ),
                    title: Text(activity.name),
                    subtitle: Text(howmanydaysleft(activity.daysLeft),
                    ),
                    trailing: Icon(Icons.chevron_left),
                    isThreeLine: false,
                  ),
                  ConstrainedBox(
                    constraints: const BoxConstraints(minWidth: double.infinity),
                    child: LinearPercentIndicator(
                            animation: true,
                            lineHeight: 15.0,
                            animationDuration: 500,
                            percent: completed / 100.0,
                            center: Text(completed.toString() + "%"),
                            linearStrokeCap: LinearStrokeCap.roundAll,
                            progressColor: colorGreenPrimary,
                          ),
                  ),
                  SizedBox(height: 10.0),
              ],
            ),
            ),

Screenshot截屏

The title property of the ListTile basically does what you need. ListTile 的title属性基本上可以满足您的需要。 Wrap your text in a column and add the progress indicator after your text.将您的文本包装在一个列中,并在您的文本之后添加进度指示器。

This should do the trick:这应该可以解决问题:

Card(
    child: ListTile(
        leading: CircleAvatar(
        backgroundImage:
            AssetImage("assets/vegetables/" + activity.cropImgUrl),
        backgroundColor: Colors.white,
        ),
        title: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
            Text(activity.name),
            LinearPercentIndicator(
            animation: true,
            lineHeight: 15.0,
            animationDuration: 500,
            percent: completed / 100.0,
            center: Text(completed.toString() + "%"),
            linearStrokeCap: LinearStrokeCap.roundAll,
            progressColor: colorGreenPrimary,
            ),
        ],
        ),
        subtitle: Text(
        howmanydaysleft(activity.daysLeft),
        ),
        trailing: Icon(Icons.chevron_left),
        isThreeLine: false,
    ),
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM