【问题标题】:Displaying charachters in a text widget in flutter在颤动的文本小部件中显示字符
【发布时间】:2021-07-13 14:07:48
【问题描述】:

如何在 Flutter 中的文本小部件中显示类似的内容?

【问题讨论】:

  • 文本小部件接受一个字符串。因此,将字符传递给它不会有问题。 Text("Mon,19 Apr . 6:00 PM")
  • 根据你的解决方案,这给了我一个时期,我想要一个实心圆,如图所示。
  • 它也支持ASCII字符。可以试试吗?

标签: flutter flutter-web


【解决方案1】:

您可以使用 RichText ,将圆点作为圆形头像和其他 2 个小部件提供您想要的文本。

                RichText(
            text:TextSpan(
              children:[
                TextSpan(
                  text:"Mon, 19 April ",
                  style:TextStyle(
                    color:Colors.blueAccent,
                  ),
                ),
                WidgetSpan(
                  child: Padding(
                    padding: EdgeInsets.symmetric(vertical:5.0,),
                    child: CircleAvatar(
                      radius:3,
                      backgroundColor:Colors.blueAccent,
                    ),
                  ),
                ),
                TextSpan(
                  text:" 06:00 PM",
                  style:TextStyle(
                    color:Colors.blueAccent,
                  ),
                ),
              ]
            ),
          ),

希望它对你有用。

【讨论】:

  • 感谢 Vinay,它确实按预期工作。但是如何在两个 TextSpan 之间留出空间,我不能在这里使用 SizedBox 小部件..
  • 您可以像我使用的那样使用 WidgetSpan 并将 Sized Box 作为其子级。
猜你喜欢
  • 2019-05-17
  • 2019-03-19
  • 2018-11-18
  • 2021-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-10
  • 2021-08-25
相关资源
最近更新 更多