SubProvider0<R> constructor

const SubProvider0<R>({
  1. required SubValueBuilderCreate<R> create,
  2. SubValueBuilderUpdate<R>? update,
  3. SubValueBuilderKeys? keys,
  4. SubValueBuilderDispose<R>? dispose,
  5. TransitionBuilder? builder,
  6. Widget? child,
})

Manages a Value T and exposes it to its descendants. Allows for smart Provider-Provider dependencies.

This is a combination of a SubValue and a Provider. Unlike a ProxyProvider where dependencies are sideloaded, this Widget completely recreates the Value when dependencies change.

The create function recieves all Providers which this depends on. The Providers are additionally treated as keys, so create is called again, should the Providers this SubProvider depends on change.

An example of a ProxyProvider

ProxyProvider<MyModel, MyOtherModel>(
  create: (_) => MyOtherModel(),
  update: (_, myModel, myOtherModel) => myOtherModel
    ..myModel = myModel,
  child: /* ... */,
);

looks like this as a SubProvider:

SubProvider<MyModel, MyOtherModel>(
  create: (_, myModel) => MyOtherModel(myModel: myModel),
  child: /* ... */,
);

The notable difference being, that myModel can now once again be passed through the constructor, and does not have to be sideloaded. MyOtherModel is automatically recreated whenever myModel changes.

Just like Providers, SubProviders can be used inside of a MultiProvider.

Implementation

const SubProvider0({
  required super.create,
  super.update,
  super.keys,
  super.dispose,
  this.builder,
  super.child,
});