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 notifiercreatemakes is disposed of when this widget leaves the tree; one given to ChangeNotifierProvider.value is not. -
Consumer<
T> -
Shows what builder returns for the
Tof 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
Aand theBof the providers above, as Consumer does for one. -
DeferredInheritedProvider<
C, T> -
Provides a
Twhose values a controllerCgives over time, as a future or a stream gives them:FutureProviderandStreamProviderare made of it. -
FutureProvider<
T> -
Provides the value of a Future:
initialDatauntil it completes, then what it completes with, the widgets that watch it rebuilt then. -
InheritedContext<
T> -
The element of a provider, as its
startListeninggets it. -
InheritedProvider<
T> -
Provides a
Tto the widgets below it, which find it by its type:context.read<T>(),context.watch<T>(),context.select, Provider.of, aConsumer. 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.readin itscreate), andchildfinds them all. -
Provider<
T> -
Provides a
Tto the widgets below it, which find it by its type:context.read<T>(),context.watch<T>(),context.select, of, aConsumer. -
ProxyProvider<
T, R> -
Provides the
Rupdatemakes from the value of the provider of aTabove and theRit made before, made anew each time that value changes, as ProxyProvider0 provides it. -
ProxyProvider0<
R> -
Provides the
Rupdatemakes from the one it made before, and makes it anew each time this widget is replaced or a providerupdatedepends on (Provider.of(context),context.watch) changes: the widgets that watch it are rebuilt when the new value is not==the one before (or asupdateShouldNotifysays), which is then handed todispose. -
ProxyProvider2<
T, T2, R> -
Provides the
Rupdatemakes from the values of the providers of aTand of aT2above, as ProxyProvider provides it. -
Selector<
A, S> -
Shows what builder returns for what selector picks from the
Aof 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.childis handed to builder, as a Consumer's is. -
Selector2<
A, B, S> -
Shows what builder returns for what selector picks from the
Aand theBof 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:
initialDatauntil it gives one, the widgets that watch it rebuilt by each that is not==the one before (or asupdateShouldNotifysays). -
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
controllerfor the valueselementprovides, each handed tosetState, the first before it returns;valueis 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 aTabove, andprevious, the value it made before (orcreatemade), 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
Tand of aT2above, as ProxyProviderBuilder does. -
ShouldRebuild<
T> = bool Function(T previous, T next) -
Whether a Selector builds again now that what it selects went from
previoustonext. -
StartListening<
T> = VoidCallback Function(InheritedContext< T?> element, T value) -
Starts listening to
value, whichelementprovides, 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
previoustocurrent.
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 anint.