ProxyProvider3<T, T2, T3, R> class

A provider that builds a value based on other providers.

The exposed value is built through builder, and then passed to InheritedProvider.

As opposed to the builder parameter of Provider, builder may be called more than once. It will be called once when the widget is mounted, then once whenever any of the InheritedWidget which ProxyProvider depends emits an update.

ProxyProvider comes in different variants such as ProxyProvider2. This only changes the builder function, such that it takes a different number of arguments. The 2 in ProxyProvider2 means that builder builds its value from 2 other providers.

All variations of builder will receive the BuildContext as first parameter, and the previously built value as last parameter.

This previously built value will be null by default, unless initialBuilder is specified – in which case, it will be the value returned by initialBuilder.

builder must not be null.

Note:

While ProxyProvider has built-in support with Provider.of, it works with any InheritedWidget.

As such, ProxyProvider2<Foo, Bar, Baz> is just syntax sugar for:

ProxyProvider<Foo, Baz>(
  builder: (context, foo, baz) {
    final bar = Provider.of<Bar>(context);
  },
  child: ...,
)

And it will also work with other .of patterns, including Scrollable.of, MediaQuery.of, and many more:

ProxyProvider<Foo, Baz>(
  builder: (context, foo, _) {
    final mediaQuery = MediaQuery.of(context);
    return Baz(mediaQuery.size);
  },
  child: ...,
)

This previous example will correctly rebuild Baz when the MediaQuery updates.

See also:

Inheritance

Constructors

ProxyProvider3({Key key, ValueBuilder<R> initialBuilder, @required ProxyProviderBuilder3<T, T2, T3, R> builder, UpdateShouldNotify<R> updateShouldNotify, Disposer<R> dispose, Widget child })
Initializes key for subclasses.

Properties

builder ProxyProviderBuilder3<T, T2, T3, R>
Builds the value passed to InheritedProvider by combining InheritedWidget. [...]
read-only
child Widget
The widget that is below the current Provider widget in the tree.
final, inherited
dispose Disposer<R>
Optionally allows to clean-up resources when the widget is removed from the tree.
final, inherited
hashCode → int
The hash code for this object.
read-only, inherited
initialBuilder ValueBuilder<R>
Builds the initial value passed as previous to didChangeDependencies.
final, inherited
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited
updateShouldNotify UpdateShouldNotify<R>
The UpdateShouldNotify passed to InheritedProvider.
final, inherited

Methods

build(BuildContext context, R value) Widget
An equivalent of StatelessWidget.build.
inherited
cloneWithChild(Widget child) → NumericProxyProvider<T, T2, T3, Void, Void, Void, R>
Clones the current provider with a new child.
inherited
createElement() ProxyProviderElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
inherited
createState() → _ProxyProviderState<R>
Creates the mutable state for this widget at a given location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
inherited
didChangeDependencies(BuildContext context, R previous) → R
Builds the value passed to build by combining InheritedWidget.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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.debug }) → String
Returns 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 ==(dynamic other) → bool
The equality operator.
inherited