PropertyWidget<T extends Object> class
An Widget that accepts a property and automatically rebuilds when the property is changed by setting Property.value or calling Property.update method or the Property.changed signal is emitted by the user.
The type is used to verify that the property supplied indeed is the right one. Since multiple properties can have different types, there's no need to specify type in that case.
Let us assume you need a property for a count. You can create the property in the following way:
final _count = 0.property; //private globals are fine.
final _count = Property<int>(0); // this works as well but ugly.
Now to create a widget that shows this count and also updates when the count changes, you can use the PropertyWidget:
PropertyWidget(
property: _count,
builder: (context) => Text(
_count.value.toString(),
style: Theme.of(context).textTheme.headlineMedium,
),
),
Let us assume you have a class like this:
class Count {
Count(this.count);
int count;
}
Create a property out of this class like this:
final _count = Count(0).property;
You can update the property like this:
_count.value = Count(1);
Though this works we don't want to create a new object here. This would have been fine if count was made of an int like this:
final _count = 0.property;
//update like this;
_count.value = 2;
To change the interior of the value that is stored in the property use the Property.update method.
_count.update((value) { value.count = 2 });
If you just update the value directly, the property widget won't update the ui unless you emit the Property.changed signal as well.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- PropertyWidget
Constructors
-
PropertyWidget({Key? key, Property<
T> ? property, Set<Property< ? properties, required Widget builder(BuildContext context), VoidCallback? onInit, VoidCallback? onDispose})Object> > -
const
Properties
- builder → Widget Function(BuildContext context)
-
The builder for the widget that uses the property.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onDispose → VoidCallback?
-
A callback which does some work when the widget is disposed.
final
- onInit → VoidCallback?
-
A callback which does some work when the widget is created.
final
-
properties
→ Set<
Property< ?Object> > -
Field for connecting to multiple properties.
final
-
property
→ Property<
T> ? -
The property that the builder uses. Use when connecting only one property.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< PropertyWidget< Object> > -
Creates the mutable state for this widget at a given 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, int wrapWidth = 65}) → 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