CellWidget class abstract
A widget which is rebuilt in response to changes in the values of ValueCell's.
When the value of a ValueCell is referenced within the build method, using ValueCell.call, the widget is automatically rebuilt whenever the value of the referenced cell changes.
Example:
class Example extends WidgetCell {
final ValueCell<int> a;
Example({
super.key
required this.a
});
@override
Widget build(BuildContext context) {
return Text('The value of cell a is ${a()}');
}
}
In the above example, the widget is rebuilt automatically whenever the
value of cell a
is changed.
Cells defined directly within the build will have their state persisted between builds. For this to happen the following rules have to be observed:
- Cells should not be defined in conditionals or loops.
- Cells should not be defined in callback or builder functions of widgets nested in this widget.
The following is an example of correctly placed cell definitions:
@override
Widget build (BuildContext context) {
final count = MutableCell(0);
final next = ValueCell.computed(() => count() + 1);
...
}
The following is an example of incorrectly placed cell definitions:
@override
Widget build (BuildContext context) {
if (...) {
// This is bad because the definition appears within a conditional
final count = MutableCell(0);
}
while (...) {
// This is bad because the definition appears within a loop
final count = MutableCell(0);
}
return Builder((context) {
// This is bad because the definition appears in a builder function
// of a nested widget and the [CellWidget] will not be able to persist
// its state between builds.
final count = MutableCell(0);
});
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- CellWidget
Constructors
- CellWidget({Key? key, String? restorationId})
-
const
- CellWidget.builder(Widget builder(CellHookContext context), {Key? key, String? restorationId})
-
Create a CellWidget with the build method defined by
builder
.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- restorationId → String?
-
Restoration ID to use for restoring the cell state
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
inherited
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited