简体   繁体   English

ListTile 中的前导图像溢出

[英]Leading Image overflows in ListTile

I have a ListView with ListTile .我有一个ListViewListTile Each ListTile has a title with Text , subtitle with Text , and leading with an Image .每个ListTile都有一个带有Texttitle 、带有Text leading subtitle和带有Image的开头。

Now, the Image is too big and vertically stretches into the next row, overlapping the Image there.现在,图像太大,垂直延伸到下一行,在那里与图像重叠。

How can I make sure that the Image stays within the bounds?如何确保图像保持在范围内?

EDIT:编辑:

I'd like not to give the image a fixed size, but rather let it adjust to the height of the list tile as given by title+subtitle's intrinsic height.我不想给图像一个固定的大小,而是让它根据标题+副标题的固有高度调整到列表块的高度。

在此处输入图片说明

You should use CircleAvatar as leading in your ListTile .您应该在ListTile使用CircleAvatar作为leading It has a radius property also that you can change, if you wish.如果您愿意,它也有一个radius属性,您可以更改该属性。

leading: CircleAvatar(
  backgroundImage: AssetImage("..."), // no matter how big it is, it won't overflow
),

在此处输入图片说明

If you wanna use rectangle image, you an use如果你想使用矩形图像,你可以使用

leading: ConstrainedBox(
  constraints: BoxConstraints(
    minWidth: 44,
    minHeight: 44,
    maxWidth: 64,
    maxHeight: 64,
  ),
  child: Image.asset(profileImage, fit: BoxFit.cover),
),

Do this:做这个:

leading: SizedBox(
  height: 100.0,
  width: 100.0, // fixed width and height
  child: Image.asset(...)
)

My code and with a picture with subtitle and tile looks like below我的代码和带有副标题和平铺的图片如下所示

  Widget _buildRow(WordPair pair) {
    return ListTile(
      title: Text(
        'Title of messages comes here',
        style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
      ),
      subtitle: Text(
        pair.asPascalCase,
        style: _font,
      ),
      leading: ConstrainedBox(
        constraints: BoxConstraints(
          minWidth: 44,
          minHeight: 44,
          maxWidth: 44,
          maxHeight: 44,
        ),
        child: Image.asset('assets/message_lock.png', fit: BoxFit.cover),
      ),
    );
  }

[1]:https://i.stack.imgur.com/1dNTk.png

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

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