允许一个小部件溢出到另一个小部件
问题内容:
我试图达到让一个小部件溢出到其他窗口的效果
所看到这里
我到目前为止的代码是这样的:
@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,
),
))
]);
}
这导致以下情况,正方形被容器切除。
还有其他方法吗?
问题答案:
一般来说,您 永远 都 不要 在抖动中溢出。
如果需要特定的布局,则需要在不同的层上显式分离“溢出”窗口小部件。
一种解决方案是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,
),
)
],
);