It shows as below, you can see the layers all in the same position but different size. The upper layer just put upon the bottom one, just like a book with different pages put on a table.
The parameters are a bit less for us. But should tell you how to use them.
alignment
We have used the alignment in the Container. It is the same as the alignment in the Container. You can find more detail in the Widgets 01 | Container. I just give an example here to describe it here.
It will show you as follows.The loose make the children widget as small as possible, the expand set the children as large as possible. The passthrough will depend on its parent widget.
overflow
This parameter will control the children widget. When its content outside the Stack. whether the children widget will be visible or clip. Let's look at an example.
Widget _overVisibleStack() => Container(
margin: EdgeInsets.only(top: 10),
color: BLUE_LIGHT,
constraints: BoxConstraints.expand(height: 40),
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Positioned(
top: 15,
child: Text(
"Flutter Open is too long to draw here, it will be visible.\n666666666666666666666666666666666",
style: TextStyle(color: TEXT_BLACK_LIGHT),
),
)
],
),
);
Widget _overClipStack() => Container(
margin: EdgeInsets.only(top: 10),
color: BLUE_LIGHT,
constraints: BoxConstraints.expand(height: 40),
child: Stack(
overflow: Overflow.clip,
children: <Widget>[
Positioned(
top: 15,
child: Text(
"Flutter Open is too long to draw here, it will be cliped.\n666666666666666666666666666666666",
style: TextStyle(color: TEXT_BLACK_LIGHT),
),
)
],
),
);
It will show you like this. The first one shows the contents, but two cut the part that outside the Stack.
Positioned
It isn't the parameter of the Stack, but it relates to the Stack. It will help you locate the children widgets in the Stack. Let's look at its constructor.
The parameters, left, top, right, and bottom will control the distance inside the Stack. If we set left: 10, this Positioned will locate at the position at the Stack that the distance from the left of the Stack is 10. Let's look at an example.
The Stack is very common in the flutter. If you have a layout that doesn't have a simple direction, such as horizontal, vertical. You can consider this layout.