允许小部件溢出到另一个小部件

Ome*_*mer 6 flutter

我试图达到让一个小部件溢出到其他窗口的效果
所看到这里

我到目前为止的代码是这样的:

  @override
  Widget build(BuildContext context) {
    Size screenSize = MediaQuery.of(context).size;
    return new Column(children: <Widget>[
      new Container(
      color: Colors.blue,
      height: screenSize.height / 2,
      width: screenSize.width,
      child: new Center(
        child: new Container(
          margin: const EdgeInsets.only(top: 320.0),
          color: Colors.red,
          height: 40.0,
          width: 40.0,
        ),
      ))
]);
}
Run Code Online (Sandbox Code Playgroud)

这导致以下情况,正方形被容器切断。
还有另一种方法吗?

Rém*_*let 10

一般来说,你永远不应该在颤振中溢出。

如果你想要一个特定的布局,你需要在不同的层上明确地分离“溢出”小部件。

一种解决方案是Stack小部件,它允许小部件位于彼此之上。

最终实现这一点:

在此处输入图片说明

颤振代码将是

new Stack(
  fit: StackFit.expand,
  children: <Widget>[
    new Column(
      mainAxisSize: MainAxisSize.max,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        new Expanded(
          child: new Container(
            color: Colors.blue,
          ),
        ),
        new Expanded(
          child: new Container(
            color: Colors.white,
          ),
        ),
      ],
    ),
    new Center(
      child: new Container(
        color: Colors.red,
        height: 40.0,
        width: 40.0,
      ),
    )
  ],
);
Run Code Online (Sandbox Code Playgroud)