首页 > 解决方案 > [FLUTTER]:根据 ListTile 的高度剪切文本

问题描述

我有以下小部件。问题是我需要根据ListTile. 现在,高度ListTile取决于我拥有的子字符串的长度。更长的是我的子字符串,更长的是ListTile. 看起来很尴尬。放入小部件是好的,但子字符串与下一个ListTile内容重叠。它看起来也很糟糕。我想,另一个解决方案是使用。但是,我需要每个的固定大小,而不改变fontSize。这就是为什么不适合我:) 它改变了字体大小。当它到达. 我该如何解决这个问题?ContainerListTileFittedBoxListTileFixedBoxListTile

InkWell(
  onTap: () {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (_) => ProductScreen(product),
      ),
    );
  },
  child: Column(
    children: [
      Container(
        padding: const EdgeInsets.symmetric(
          vertical: 8.0,
          horizontal: 4.0,
        ),
        child: ListTile(
          title: Text(
            product.title.toUpperCase(),
            style: Styles.listTitleStyle,
          ),
          subtitle: Text(
            product.description,
            style: Styles.listBodyStyle,
          ),
        ),
      ),
      const Divider(height: 1.0),
    ],

标签: stringflutterdarttext

解决方案


为您的文本小部件添加类似这样的内容,

subtitle: Text(
    maxLines: 2,   //customize your number of lines
    overflow: TextOverflow.ellipsis,    //add this to set (...) at the end of sentence 
    product.description,
    style: Styles.listBodyStyle,
),

推荐阅读