我有一个定位的Text元素,它位于Stack中的Image元素之上.我想将一个简单的背景颜色应用于该Text元素,以便它像文本框一样构成文本框架:
我可以通过在该堆栈中插入一个Container作为另一个定位子项来完成此操作.但是每次文本字符串更改时我都必须重新计算宽度,这是次优的.有没有更好的办法?
var stack = new Stack(
children: <Widget>[
new Image.asset ( // background photo
"assets/texture.jpg",
fit: ImageFit.cover,
height: 600.0,
),
new Positioned ( // headline
child: new Container(
decoration: new BoxDecoration (
backgroundColor: Colors.black
),
),
left: 0.0,
bottom: 108.0,
width: 490.0,
height: 80.0,
),
new Positioned (
child: new Text (
"Lorem ipsum dolor.",
style: new TextStyle(
color: Colors.blue[500],
fontSize: 42.0,
fontWeight: FontWeight.w900
)
),
left: 16.0,
bottom: 128.0,
)
]
);
Run Code Online (Sandbox Code Playgroud)