0

如果我有一个长标题,根据字符串的长度分成两行,则正文文本在 Container 小部件内剪裁不正确

在此处输入图像描述

Expanded(
 child: Container(
   height: MediaQuery.of(context).size.height / 7.5,
   padding: EdgeInsets.only(right: 8),
   child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Text(
          'HERE SOME LONG HEADLINE, WITH 1 or 2 Lines'
       
          maxLines: 2,
          overflow: TextOverflow.ellipsis,
        ),
        SizedBox(
        height: 3.0,
        ),
        Expanded(
         child: Text(
           'here some long body text over more lines, which is cut wrong when the headline is two lines',
           overflow: TextOverflow.ellipsis,
           softWrap: true,
           maxLines: 5,
           textAlign: TextAlign.left,
         ),
        ),
      ],
    ),
  ),
),
4

1 回答 1

0

I believe some widget wrapping your Text widgets, is limiting the amount of space they have, hence the clipping. Without the full widget tree, it's not possible to be sure which.

Your containing Container widget has a height specified. If you remove this, do your text widgets still clip?

Expanded(
 child: Container(
   height: MediaQuery.of(context).size.height / 7.5, // ← try removing this
   padding: EdgeInsets.only(right: 8),

Also, perhaps this package might be interesting: AutoSizeText.

于 2021-02-22T18:11:29.983 回答