简体   繁体   English

如何让 Positioned 小部件在 Stack (flutter) 中工作?

[英]How can I get the Positioned widget to work in a Stack (flutter)?

Is something wrong with this snippet?这个片段有问题吗? The positioned element isn't showing up but the others are.定位元素没有显示,但其他元素显示。 deviceHeight is defined elsewhere as the height of the device. deviceHeight 在别处定义为设备的高度。

The first container holds the other two containers under it.第一个容器将另外两个容器放在它下面。 The second container appears at the top correctly, but the third one (positioned) which should be under the second one doesn't appear.第二个容器正确显示在顶部,但应该在第二个容器下方的第三个(定位)没有出现。 Welcome to hear any alternatives.欢迎听到任何替代方案。

Align(
    alignment: Alignment.bottomCenter,
    child: Stack(children: <Widget>[
      Container(
        color: Color(bgDark),
        height: deviceHeight / 100 * 40,
      ),
      Container(color: Colors.red, height: deviceHeight / 18),
      Positioned(
          top: 50,
          child: Container(
              color: Colors.green, height: deviceHeight / 1))
    ]))

Adding a width to the Positioned Container made it visible.Positioned Container添加width使其可见。

Align(
      alignment: Alignment.bottomCenter,
      child: Stack(
        children: <Widget>[
          Container(
            color: Colors.blue,
            height: 300,
          ),
          Container(
            color: Colors.red,
            height: 200,
          ),
          Positioned(
            top: 50,
            child: Container(
              color: Colors.green,
              height: 100,
              width:100,
            ),
          ),
        ],
      ),
    );

I am not sure about the exact cause of the issue but it seems Positioned needed both height and width dimensions.我不确定问题的确切原因,但似乎Positioned需要heightwidth尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM