【问题标题】:How can I get the Positioned widget to work in a Stack (flutter)?如何让 Positioned 小部件在 Stack (flutter) 中工作?
【发布时间】:2020-10-10 04:18:03
【问题描述】:

这个sn-p有什么问题吗?定位元素没有显示,但其他元素显示。 deviceHeight 在别处定义为设备的高度。

第一个容器将另外两个容器放在它下面。第二个容器正确显示在顶部,但应该在第二个容器下方的第三个(定位)没有出现。欢迎听到任何替代方案。

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))
    ]))

【问题讨论】:

  • width 添加到Positioned Container 使其可见。我假设随机的 heightwidth 值,例如下面给出的答案。

标签: flutter dart


【解决方案1】:

width 添加到Positioned Container 使其可见。

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,
            ),
          ),
        ],
      ),
    );

我不确定问题的确切原因,但似乎 Positioned 需要 heightwidth 尺寸。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-09
    • 2021-03-31
    • 2020-09-09
    • 1970-01-01
    • 2020-09-29
    • 2021-10-04
    • 1970-01-01
    • 2016-08-05
    相关资源
    最近更新 更多