首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止文本在颤动中溢出

防止文本在颤动中溢出
EN

Stack Overflow用户
提问于 2020-11-25 22:19:39
回答 4查看 297关注 0票数 1

我正在从db加载数据。有时我会得到更长的字符串,这会导致文本溢出。如何使溢出文本转到下一行?

代码语言:javascript
复制
Padding(
              padding: const EdgeInsets.all(5),
              child: Card(
                color: (list[index]['author'] == widget.user.email) ? Colors.greenAccent : Colors.grey[900],
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    CircleAvatar(
                      radius: 40,
                      backgroundImage: NetworkImage(list[index]['profilePicUrl']),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(left: 60),
                      child: Column(
                        children: <Widget>[
                          Text(list[index]['message'],softWrap: false, overflow: TextOverflow.clip, style: TextStyle(color: (list[index]['author'] == widget.user.email) ? Colors.black : Colors.white, fontSize: 20)),
                          Text(list[index]['author'], style: TextStyle(color: (list[index]['author'] == widget.user.email) ? Colors.grey[800] : Colors.grey, fontSize: 15)),
                      ],
                      ),
                    ),
                  ],
                ),
              ),
            );
EN

回答 4

Stack Overflow用户

发布于 2020-11-25 22:28:26

您需要将Column包装在Expanded中,以下是小部件树的示例代码:

代码语言:javascript
复制
Row(
  mainAxisAlignment: MainAxisAlignment.start,
  children: <Widget>[
    Expanded( // <-- This is what you need
      child: Column(
        children: <Widget>[
          Text(
            'This is very long line which can overflow on small screen devices easily',
            softWrap: false,
            overflow: TextOverflow.ellipsis,
          ),
          Text('author'),
        ],
      ),
    ),
  ],
)
票数 1
EN

Stack Overflow用户

发布于 2020-11-25 22:30:48

尝试将文本换行为灵活的

代码语言:javascript
复制
Flexible(
  child: Text('Some lengthy text for testing'),
)
票数 0
EN

Stack Overflow用户

发布于 2020-11-26 14:05:39

您需要使用overFlow在文本小部件中添加maxLine。

代码语言:javascript
复制
                                     Text('long text here',
                                        textAlign: TextAlign.center,
                                        style: TextStyle(
                                            color:
                                                AppColors.subHeadingColor,
                                            fontFamily: 'Rubik',
                                            fontWeight:
                                                FontConstants.rubikMedium),
                                        maxLines: 2,
                                        overflow: TextOverflow.ellipsis,
                                      ),
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65006521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档