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

Pri*_*nca 2 text background dart flutter

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


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

            ),


Run Code Online (Sandbox Code Playgroud)

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

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

在此处输入图片说明

Sae*_*bil 5

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

检查这个

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