Overview
Stack positions its children on top of each other, following a LIFO (Last In First Out) order. The last control in the list is displayed on top. This control is useful for overlaying controls, creating complex UI compositions, or implementing implicit animations that require knowing absolute positions.Basic Example
Class Definition
Properties
controls
A list of controls to display.For the display order, it follows the order of the list, so the last control in the list will be displayed on top (LIFO - Last In First Out).Controls can be positioned absolutely using the
top, left, right, and bottom properties on the control itself.clip_behavior
The content will be clipped (or not) according to this option.Options:
ClipBehavior.HARD_EDGE- Clip content with hard edgesClipBehavior.ANTI_ALIAS- Clip with anti-aliasingClipBehavior.ANTI_ALIAS_WITH_SAVE_LAYER- Clip with anti-aliasing and save layerClipBehavior.NONE- No clipping
alignment
Specifies the alignment for non-positioned controls (those without explicit
top, left, right, or bottom properties) and partially-positioned controls.Examples:ft.alignment.center- Center alignmentft.alignment.top_left- Top-left alignmentft.alignment.bottom_right- Bottom-right alignmentAlignment(x, y)- Custom alignment where x and y range from -1.0 to 1.0
fit
How to size the non-positioned controls.Options:
-
StackFit.LOOSE- The constraints from parent are loosened. For example, if the stack has constraints that force it to 350x600, non-positioned children can have any width from 0 to 350 and any height from 0 to 600. -
StackFit.EXPAND- The constraints from parent are tightened to the biggest size allowed. For example, if the stack has loose constraints with width 10-100 and height 0-600, non-positioned children would all be sized as 100 pixels wide and 600 high. -
StackFit.PASS_THROUGH- The constraints from parent are passed unmodified to non-positioned children. For example, if a Stack is an expanded child of a Row, the horizontal constraints will be tight and the vertical constraints will be loose.
Layout Behavior
How Children Are Arranged
- Z-Order: Controls are stacked in the order they appear in the list. The first control is at the bottom, and the last control is on top.
-
Non-Positioned Controls: Controls without explicit positioning properties are placed according to the
alignmentproperty and sized according to thefitproperty. -
Positioned Controls: Controls with
top,left,right, orbottomproperties are positioned absolutely within the Stack:
Positioning Controls
You can position controls absolutely by setting their layout properties:top: Distance from the top edgeleft: Distance from the left edgeright: Distance from the right edgebottom: Distance from the bottom edge
Examples
Image with Text Overlay
Positioned Badges
Centered Overlay
Card with Corner Button
StackFit Enum
TheStackFit enum controls how non-positioned children are sized:
LOOSE Example
EXPAND Example
Use Cases
- Image Overlays: Add text, gradients, or buttons over images
- Badges: Position notification badges on icons or avatars
- Complex Layouts: Create intricate UI designs with overlapping elements
- Animations: Implement implicit animations with absolute positioning
- Loading Indicators: Show spinners over content
- Watermarks: Add watermarks to images or content