简体   繁体   English

[FLUTTER]:根据 ListTile 的高度剪切文本

[英][FLUTTER]: Cut text depending of height of ListTile

I have the following widget.我有以下小部件。 The problem is I need to cut my subtitle string depending on the height and width of the ListTile .问题是我需要根据ListTile的高度和宽度剪切我的字幕字符串 Now, height of the ListTile depends on length of substring I have.现在,ListTile 的高度取决于我拥有的ListTile的长度。 Longer is my substring, longer is the height of the ListTile .更长的是我的 substring,更长的是ListTile的高度。 It looks awkward.看起来很尴尬。 Putting ListTile inside Container widget is good, but the substring overlaps the next ListTile content.ListTile放在Container小部件中很好,但 substring 与下一个ListTile内容重叠。 it looks terrible too.它看起来也很糟糕。 Another solution was using FittedBox , I thought.我想,另一个解决方案是使用FittedBox But, I need the fixed size of each ListTile , without changing the fontSize .但是,我需要每个ListTile的固定大小,而不更改fontSize That's why the FixedBox doesn't fit me:) It changes the fontSize.这就是为什么FixedBox不适合我的原因:) 它改变了 fontSize。 I need to cut my string when it reaches the end of the ListTile .当它到达ListTile的末尾时,我需要切断我的字符串。 How can I solve this?我该如何解决这个问题?

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),
    ],

For your text widget add something like this,为您的文本小部件添加类似这样的内容,

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,
),

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

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