我有一个定位的文本元素,它位于Stack中的Image元素的顶部.我想将简单的背景 colored颜色 应用到该文本元素,以便它将文本的边框设置为标题框:
我可以通过在该堆栈中插入一个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,
)
]
);