首页 > 解决方案 > 如何在 Wrap Widget 中换行

问题描述

我使用 Wrap Widget 来显示聊天消息,我无法在 Wrap Widgets 中显示新行 '\n'

显示短信:

a *bold*
`highlight`
```pre```
```pre1```
a ```pre2```
a *bold*

提取到列表小部件: 在此处输入图像描述

然后将 listWidget 包装在 Wrap Widget

Wrap(
  children: listWidgets,
)

在此处输入图像描述

但文本小部件 ('\ n') 没有按预期进行

是否有人在 Wrap Widget 中有解决方案新行请帮助

标签: flutterflutter-layout

解决方案


尝试使用 RichText 小部件:

RichText(
                text: TextSpan(
                  text: '26 Sep 2020\n\n',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 12.0,
                  ),
                  children: <TextSpan>[
                    TextSpan(
                      text: 'blablabla',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                        fontSize: 16.0,
                      ),
                    ),
                  ],
                ),
              ),

推荐阅读