容器未采用 BoxDecoration 图像的大小

Waz*_*zza 5 dart flutter

我想将以下容器添加到 ListView,但该容器不采用作为装饰添加的图像的大小。如果我将图像添加为容器的子项,它工作正常,但我也想在图像顶部显示文本。

var imageListView = new List<Container>();
var container1 = new Container(
  margin: EdgeInsets.all(8.0),
  alignment: Alignment.bottomLeft,
  child: new Text('Order of The Day',
      style: new TextStyle(
          fontFamily: 'CallingAngelsPersonalUse',
          fontSize: 20.0,
          color: Colors.white
      ),
  ),
  decoration: new BoxDecoration(
    image: new DecorationImage(
      image: new AssetImage('assets/SVSunset.jpg'),
      fit: BoxFit.cover,
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)

将容器添加到 ListView 然后显示如下:

imageListView.add(container1);

new ListView(children: imageListView)
Run Code Online (Sandbox Code Playgroud)

谁能看到我缺少什么吗?

Waz*_*zza 8

我设法通过将所有内容放入堆栈并定位文本来解决此问题,如下所示:

var container1 = new Container(
  margin: EdgeInsets.all(8.0),
  child: new Stack(
    children: <Widget>[
      new Image(image: new AssetImage('assets/SVSunset.jpg')),
      new Positioned(
        left: 8.0,
        bottom: 8.0,
        child: new Text('Order of the day',
          style: new TextStyle(
              fontFamily: 'CallingAngelsPersonalUse',
              fontSize: 30.0,
              color: Colors.white
          ),
        ),
      )
    ],
  ),
);
Run Code Online (Sandbox Code Playgroud)