provider library

Provider for widgets of the twk package, as package:provider is for Flutter's: values provided to a subtree and found by their type (context.read, context.watch, context.select), the widgets that depend on them rebuilt when they change.

Provider provides a value, ChangeNotifierProvider and ListenableProvider a listenable, ValueListenableProvider the value of one, FutureProvider and StreamProvider what a future or a stream gives, ProxyProvider and ProxyProvider2 one made from others; MultiProvider nests them. Consumer, Consumer2 and Selector build with what they provide.

Classes

ChangeNotifierProvider<T extends ChangeNotifier?>
Provides a ChangeNotifier T, as ListenableProvider provides a listenable: the notifier create makes is disposed of when this widget leaves the tree; one given to ChangeNotifierProvider.value is not.
Consumer<T>
Shows what builder returns for the T of the provider above, built again each time it changes; the widgets around it are not rebuilt. child, built once by the parent, is handed to builder, for what does not depend on the value.
Consumer2<A, B>
Shows what builder returns for the A and the B of the providers above, as Consumer does for one.
DeferredInheritedProvider<C, T>
Provides a T whose values a controller C gives over time, as a future or a stream gives them: FutureProvider and StreamProvider are made of it.
FutureProvider<T>
Provides the value of a Future: initialData until it completes, then what it completes with, the widgets that watch it rebuilt then.
InheritedContext<T>
The element of a provider, as its startListening gets it.
InheritedProvider<T>
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.
ListenableProvider<T extends Listenable?>
Provides a Listenable T, as Provider provides a value, and tells the widgets that depend on it each time it notifies its listeners: it listens from the first time the listenable is read until it is replaced or this widget leaves the tree.
MultiProvider
The providers one inside another, the first outermost, around child: MultiProvider(providers: [Provider(create: …), …], child: …) for as many nested providers, each a SingleChildWidget without a child of its own. A provider finds those before it in the list (context.read in its create), and child finds them all.
Provider<T>
Provides a T to the widgets below it, which find it by its type: context.read<T>(), context.watch<T>(), context.select, of, a Consumer.
ProxyProvider<T, R>
Provides the R update makes from the value of the provider of a T above and the R it made before, made anew each time that value changes, as ProxyProvider0 provides it.
ProxyProvider0<R>
Provides the R update makes from the one it made before, and makes it anew each time this widget is replaced or a provider update depends on (Provider.of(context), context.watch) changes: the widgets that watch it are rebuilt when the new value is not == the one before (or as updateShouldNotify says), which is then handed to dispose.
ProxyProvider2<T, T2, R>
Provides the R update makes from the values of the providers of a T and of a T2 above, as ProxyProvider provides it.
Selector<A, S>
Shows what builder returns for what selector picks from the A of the provider above, built again only when it picks something else, as Selector0 is. The selector runs each time the value changes; the builder only then.
Selector0<S>
Shows what builder returns for what selector picks with the context, built again only when it picks something else: not ==, lists, sets, maps and other iterables compared element by element (or as shouldRebuild says), or when this widget is replaced. child is handed to builder, as a Consumer's is.
Selector2<A, B, S>
Shows what builder returns for what selector picks from the A and the B of the providers above, as Selector does for one.
SingleChildBuilder
Shows what builder returns for child: a SingleChildWidget made of a function.
SingleChildState<W extends SingleChildStatefulWidget>
The state of a SingleChildStatefulWidget: buildWithChild gets the child given to the widget, or the one a MultiProvider gives it.
SingleChildStatefulWidget
A StatefulWidget built around a child, as a SingleChildStatelessWidget is: its state is a SingleChildState.
SingleChildStatelessWidget
A StatelessWidget built around a child: buildWithChild gets the one given to the constructor, or in a MultiProvider the next widget of its list (its child, for the last).
SingleChildWidget
A widget a MultiProvider can nest: one built around a child, which it leaves out there, the next widget of the list being its child.
StreamProvider<T>
Provides the last value of a Stream: initialData until it gives one, the widgets that watch it rebuilt by each that is not == the one before (or as updateShouldNotify says).
ValueListenableProvider<T>
Provides the value of a ValueListenable, found by its type T (not the listenable's): the widgets that watch it are rebuilt each time the listenable changes it to one that is not == (or as updateShouldNotify says).

Extensions

ReadContext on BuildContext
Finds what a provider above provides.
SelectContext on BuildContext
Depends on a part of what a provider above provides.
WatchContext on BuildContext
Finds what a provider above provides, and depends on it.

Typedefs

Create<T> = T Function(BuildContext context)
Makes a provider's value: called with the provider's context, in which it may read other providers (context.read) but not depend on them.
DeferredStartListening<T, R> = VoidCallback Function(InheritedContext<R?> element, void setState(R value), T controller, R? value)
Starts listening to controller for the values element provides, each handed to setState, the first before it returns; value is the last one, null before the first. Returns what stops it.
Dispose<T> = void Function(BuildContext context, T value)
Disposes of a value a provider created, when the provider leaves the tree.
ErrorBuilder<T> = T Function(BuildContext context, Object? error)
The value a FutureProvider or a StreamProvider provides in place of error, which its future or stream gave.
ProxyProviderBuilder<T, R> = R Function(BuildContext context, T value, R? previous)
Makes a ProxyProvider's value from value, that of the provider of a T above, and previous, the value it made before (or create made), null the first time.
ProxyProviderBuilder2<T, T2, R> = R Function(BuildContext context, T value, T2 value2, R? previous)
Makes a ProxyProvider2's value from those of the providers of a T and of a T2 above, as ProxyProviderBuilder does.
ShouldRebuild<T> = bool Function(T previous, T next)
Whether a Selector builds again now that what it selects went from previous to next.
StartListening<T> = VoidCallback Function(InheritedContext<T?> element, T value)
Starts listening to value, which element provides, for the changes to tell the dependents of (InheritedContext.markNeedsNotifyDependents); returns what stops it.
UpdateShouldNotify<T> = bool Function(T previous, T current)
Whether the widgets that depend on a provider are told that its value went from previous to current.

Exceptions / Errors

ProviderNotFoundException
No provider of the type a context looked for was found above it.
ProviderNullException
A provider of a nullable type gave null where a non-nullable one was asked for: Provider<int?> read as an int.