I have a Text positional element that sits on top of an image element on the stack. I would like to apply a simple background color to this Text element so that it formats the text as a box with the inscription:
I can do this by inserting a Container as another positioned child on this stack. But I will have to recalculate the width every time the text string changes, which is not optimal. Is there a better way?
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,
)
]
);
source
share