StatelessElement
live An element that composes other elements but holds no mutable state. Override the Build method to describe the UI subtree this element represents. The framework calls Build whenever the parent rebuilds, and the returned element tree is reconciled against the previous output.
Constructor
StatelessElement
Creates a new stateless element with an optional key.
| Parameter | Description |
|---|---|
key | An optional key for reconciliation identity. |
Methods
Build
Describes the UI subtree that this element represents. Called by the framework whenever a rebuild is needed.
| Parameter | Description |
|---|---|
context | The build context providing access to the element’s position in the tree and ancestor lookup capabilities. |
Returns: An element describing the UI subtree.
ShouldRebuild
Called by the framework before rebuilding this element when its parent rebuilds. Return false to skip Build(), child reconciliation, and repaint entirely. Return true (the default) to rebuild as normal. Override this to avoid rebuilding when the new element description is equivalent to the previous one.
| Parameter | Description |
|---|---|
oldElement | The previous element description. |
newElement | The incoming element description from the parent. |
Returns: true to rebuild; false to skip.