gpt4 book ai didi

text - 如何在 flutter 中将背景颜色设置为包含文本的宽度

转载 作者:IT王子 更新时间:2023-10-29 06:39:13 32 4
gpt4 key购买 nike

我有一个文本,它基本上是一个框中的标题,我想为该文本后面的空间提供背景颜色。


Padding(
padding: EdgeInsets.all(15.0),
child: Text(
'Your Profile',
style: TextStyle(
color: Colors.blue,
fontSize: 26.0,
background: Paint()..color = Colors.blue,

),


这是我尝试过的方法,但似乎不起作用。

预期:这里“你的个人资料”文本有背景颜色,我需要实现这一点。

enter image description here

最佳答案

你可以用 Container() 包裹它,但是,很可能你必须用类似 double.maxFinite 的东西来定义宽度

检查这个

Container(
width: double.maxFinite,
color: Colors.red, //define the background color
child: Text("My Text"),
)

关于text - 如何在 flutter 中将背景颜色设置为包含文本的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56817944/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com