InheritedProvider<T> class
Provides a T to the widgets below it, which find it by its type:
context.read<T>(), context.watch<T>(), context.select,
Provider.of, a Consumer. What the other providers of this package
are made of.
The value is the one create makes, the first time it is read unless
lazy is false, then handed to dispose when this widget leaves the
tree; update makes it anew, from the one before, each time this widget
is replaced or a provider update depends on changes
(Provider.of(context)), the dependents told when the new one is not
== the old (or as updateShouldNotify says), and the old one
disposed. With InheritedProvider.value it is one made elsewhere,
neither created nor disposed: a new widget with a value that is not
== (or as updateShouldNotify says) tells the dependents.
startListening is called with the value once it is read, for a value
whose changes are to rebuild the dependents (a listenable, a stream),
and what it returns when the value is replaced or the provider leaves
the tree.
With builder, the child is what it returns for child, built below
this provider: the context it gets finds the value. Outside a
MultiProvider, one of child and builder is given.
A provider of a value that tells its dependents when a key changes it, as the other providers of this package are made:
InheritedProvider<ValueNotifier<int>>(
create: (context) => ValueNotifier(0),
startListening: (element, notifier) {
notifier.addListener(element.markNeedsNotifyDependents);
return () => notifier.removeListener(element.markNeedsNotifyDependents);
},
dispose: (context, notifier) => notifier.dispose(),
child: app,
)
- Inheritance
-
- Object
- Widget
- StatelessWidget
- SingleChildStatelessWidget
- InheritedProvider
- Implementers
Constructors
-
InheritedProvider({Key? key, Create<
T> ? create, T update(BuildContext context, T? value)?, UpdateShouldNotify<T> ? updateShouldNotify, void debugCheckInvalidValueType(T value)?, StartListening<T> ? startListening, Dispose<T> ? dispose, TransitionBuilder? builder, bool? lazy, Widget? child}) -
Provides the value
createmakes, orupdatemakes anew; one of them is given. -
InheritedProvider.value({required T value, Key? key, UpdateShouldNotify<
T> ? updateShouldNotify, StartListening<T> ? startListening, bool? lazy, TransitionBuilder? builder, Widget? child}) -
Provides
value, made and disposed of elsewhere.
Properties
- builder → TransitionBuilder?
-
Builds the child below this provider, from the one given.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Tells this widget apart from its siblings; see Key.
finalinherited
- lazy → bool
-
Whether the value is made only when it is first read; else when this
widget is placed in the tree.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
BuildContext context) → Widget -
Describes this part of the interface; called when the widget is placed
in the tree, whenever its parent gives it a new widget, and when its
element is marked dirty.
inherited
-
buildWithChild(
BuildContext context, Widget? child) → Widget -
What this widget shows around
child.override -
createElement(
) → StatelessElement -
Inflates this widget into a new element for the tree.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Adds what describes this widget in its element's description
(Element.describe) to
properties, those not worth showing (a default) left out; an override calls this first. A render object widget adds only what its render object does not show. Only Element.describe calls it: a frame never does.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited