PropertyChangeProvider<T extends PropertyChangeNotifier<S>, S extends Object> class

An InheritedWidget that provides access to a PropertyChangeNotifier to descendant widgets. The type parameter T is the type of the PropertyChangeNotifier<S> subclass. The type parameter S is the type of the properties to observe.

Given the following model:

class MyModel extends PropertyChangeNotifier<String> {...}

A descendant widget can access the model instance by using the following syntax. This will automatically register the widget to be rebuilt whenever any property changes on the model:

final model = PropertyChangeProvider.of<MyModel, String>(context).value;

To access the properties that were changed in the current build frame, use the following syntax.

final properties = PropertyChangeProvider.of<MyModel, String>(context).properties;

To register the widget to be rebuilt only on specific property changes, provide a properties parameter:

final model = PropertyChangeProvider.of<MyModel, String>(context, properties: ['foo', 'bar']).value;

To only access the model without registering the widget to be rebuilt, provide a listen parameter with a value of false:

final model = PropertyChangeProvider.of<MyModel, String>(context, listen: false).value;
Inheritance

Constructors

PropertyChangeProvider({Key? key, required T value, required Widget child})
Creates a PropertyChangeProvider that can be accessed by descendant widgets.
const

Properties

child Widget
The widget below this widget in the tree.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value → T
The instance of T to provide to descendant widgets.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _PropertyChangeProviderState<PropertyChangeNotifier<Object>, 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}) 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

Static Methods

of<T extends PropertyChangeNotifier<S>, S extends Object>(BuildContext context, {Iterable<S>? properties, bool listen = true}) PropertyChangeModel<T, S>?
Retrieves the PropertyChangeModel from the nearest ancestor PropertyChangeProvider. If listen is true (which is the default), the calling widget will also be rebuilt whenever the ancestor's PropertyChangeNotifier model changes. To only rebuild for certain properties, provide them in the properties parameter. If listen is false, the properties parameter must be null or empty.