我有一个堆栈小部件,里面有两个小部件. 一张画背景,另一张画在上面. 我希望两个小工具都有相同的大小.
我想要顶部的小部件,它是一个列,将堆栈垂直扩展并填充到背景小部件设置的大小.
我怎么才能让它工作呢?
我有一个堆栈小部件,里面有两个小部件. 一张画背景,另一张画在上面. 我希望两个小工具都有相同的大小.
我想要顶部的小部件,它是一个列,将堆栈垂直扩展并填充到背景小部件设置的大小.
我怎么才能让它工作呢?
Positioned.fill
Stack(
children: [
Positioned.fill(
child: Column(
children: [
//...
],
),
),
//...
],
);
更多关于Positioned
in Flutter Widget of the Week的信息
This is all about constraints. Constraints are min/max width/height values that are passed from the parent to its children. In the case of Stack
. The constraints it passes to its children state that they can size themselves as small as they want, which in the case of some widgets means they will be their "natural" size. After being sized, Stack
will place its children in the top left corner.
Positioned.fill
gets the same constraints from Stack
but passes different constraints to its child, stating the it (the child) must be of exact size (which meant to fill the Stack
).
Positioned.fill()
等于:
Positioned(
top: 0,
right: 0,
left: 0,
bottom:0,
child: //...
)