在以下情况下,堆栈窗口小部件在哪里进入混乱状态

时间:2018-08-12 07:30:35

标签: flutter flutter-layout

我有两个应该在屏幕上的列中延伸的容器。在这些容器的顶部,我想将卡片放在顶部或另一块材料上。 我的代码看起来像

  Column(
  children: <Widget>[
    Expanded(
      child: new Container(
        color: Colors.red,
      ),
    ),
    Expanded(
      child: new Container(
        color: Colors.green,
      ),
    ),

1 个答案:

答案 0 :(得分:1)

堆栈小部件应包含列和卡小部件。

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      textDirection: TextDirection.ltr,
      children: [
        Column(
          children: <Widget>[
            Expanded(
              child: new Container(
                color: Colors.red,
              ),
            ),
            Expanded(
              child: new Container(
                color: Colors.green,
              ),
            ),
          ],
        ),
        Center(
          child: Container(
            width: 100.0,
            height: 100.0,
            color: Colors.amberAccent,
          ),
        )
      ],
    );
  }
}

屏幕截图:

Demo