【问题标题】:Flutter Container height same as parent heightFlutter 容器高度与父高度相同
【发布时间】:2018-12-07 06:56:54
【问题描述】:

我想用白色容器覆盖卡片,但容器总是需要高度(否则不会显示)。我希望它和它的父级堆栈一样大。我怎样才能使这项工作?卡的高度不同。我想我错过了一些东西;)

return new Stack(
 children: <Widget>[
  new Card( ... ),
  new Container(color: Colors.white70),
 ]
);

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    您可以使用Positioned.fill 来强制堆栈子级填充Stack

    Stack(
      children: [
        Card(),
        Positioned.fill(
          child: Container(color: Colors.red),
        )
      ]
    );
    

    【讨论】:

    • 你拯救了我的一天!
    • 像魅力一样工作!
    【解决方案2】:
    height: double.infinity 
    

    在容器的情况下它对我有用

    【讨论】:

    • 比包装小部件更容易
    猜你喜欢
    • 1970-01-01
    • 2020-07-07
    • 2020-06-20
    • 2022-12-18
    • 2015-03-20
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多