RefenaContainer class Introduction Riverpod Initialization
The RefenaContainer holds the state of all providers. Every provider is initialized lazily.
You can override a provider by passing overrides
to the constructor.
In this case, the state of a provider is initialized right away.
A provider is stateless. The state is held by a notifier. This is also the case for Provider which is immutable. You can access any underlying notifier via RefenaContainer.anyNotifier. Ref.notifier is a more restricted version because some notifiers are not meant to be accessed directly.
A Ref is a trimmed down version of a RefenaContainer but you can always access the RefenaContainer via Ref.container. This is used to discourage low-level APIs. Another reason is that a Ref may have a custom label which is used to identify the origin of an event. Having a RefenaContainer means that you hold the original reference without any custom label or proxy instances.
- Implemented types
- Available extensions
Constructors
-
RefenaContainer({PlatformHint platformHint = PlatformHint.unknown, List<
ProviderOverride< overrides = const [], List<BaseNotifier, dynamic> >BaseProvider< initialProviders = const [], NotifyStrategy defaultNotifyStrategy = NotifyStrategy.equality, List<BaseNotifier, dynamic> >RefenaObserver> observers = const [], bool initImmediately = true}) - Creates a RefenaContainer.
Properties
- container → RefenaContainer
-
Returns the backing container.
The container exposes more advanced methods for edge cases.
no setteroverride
- debugLabel → String
-
A label to be used in debug messages and
by the
RefenaTracingPage
.no setteroverride - debugOwnerLabel → String
-
Returns the owner of this Ref.
Usually, this is a notifier or a widget.
Used by Ref.redux to log the origin of the action.
no setteroverride
- defaultNotifyStrategy → NotifyStrategy
-
The default notify strategy
final
- disposed → bool
-
Whether the container has been disposed.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- observer → RefenaObserver?
-
The provided observer (e.g. for logging)
It might be a RefenaMultiObserver if you passed multiple observers.
final
- platformHint ↔ PlatformHint
-
The platform hint.
This is used by the inspector_client to determine the host IP.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
accessor<
R> (BaseWatchable< BaseNotifier, dynamic, R> provider) → StateAccessor<R> -
Similar to Ref.read, but instead of returning the state right away,
it returns a StateAccessor to get the state later.
override
-
anyNotifier<
N extends BaseNotifier< (T> , T>BaseProvider< N, T> provider, [void onInitNotifier(BaseProvider<BaseNotifier, dynamic> , BaseNotifier)?]) → N -
Returns the notifier of a NotifierProvider.
This method can be used to avoid the constraint of
NotifyableProvider
. Useful for testing. -
cleanupListeners(
) → void - Removes disposed listeners from all notifiers. This happens regularly, but you can call it manually if you want to to visualize the current state.
-
dispose<
N extends BaseNotifier< (T> , T>BaseProvider< N, T> provider) → void -
Disposes a
provider
. Be aware that streams (ref.stream) are closed also. You may call this method in the dispose method of a stateful widget. Calling this method multiple times has no effect. Note: Theprovider
will be initialized again on next access.override -
disposeContainer(
) → void - Disposes the container itself. It will also dispose all providers. After calling this method, the container should not be used anymore.
-
disposeFamilyParam<
N extends FamilyNotifier< (dynamic, P, dynamic> , P>BaseProvider< N, dynamic> provider, P param) → void -
Disposes the
param
of a familyprovider
. While the ordinary dispose method disposes the whole provider, this method only disposes theparam
. Calling this method multiple times has no effect.override -
ensureOverrides(
) → Future< void> - Awaiting this future will ensure that all overrides are initialized. Calling it multiple times is safe.
-
exists(
BaseProvider< BaseNotifier, dynamic> provider) → bool - Whether the provider is initialized. Usually, providers are initialized when you first access them. They are also initialized when you override them. They are getting disposed when you call Ref.dispose.
-
future<
N extends GetFutureNotifier< (T> , T>ProviderAccessor< BaseProvider< provider, [void onInitNotifier(BaseProvider<N, AsyncValue< , N, AsyncValue<T> >T> >BaseNotifier, dynamic> , BaseNotifier)?]) → Future<T> -
Get the Future of an AsyncNotifierProvider, FutureProvider or
StreamProvider.
override
-
getActiveNotifiers(
) → List< BaseNotifier> - Returns all active notifiers. Remember: A provider is stateless. The notifier holds the state.
-
getActiveProviders(
) → List< BaseProvider< BaseNotifier, dynamic> > - Returns all active providers. Remember: A provider is stateless. The notifier holds the state.
-
init(
) → void - Initializes the container.
-
message(
String message) → void -
Emits a message to the observer.
This might be handy if you use
RefenaTracingPage
.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifier<
N extends BaseNotifier< (T> , T>NotifyableProvider< N, T> provider) → N -
Returns the notifier of a NotifierProvider.
override
-
read<
N extends BaseNotifier< (T> , T, R>BaseWatchable< N, T, R> watchable, [void onInitNotifier(BaseProvider<BaseNotifier, dynamic> , BaseNotifier)?]) → R -
Returns the actual value of a Provider.
override
-
rebuild<
N extends RebuildableNotifier< (T, R> , T, R>RebuildableProvider< N, T, R> provider, [LabeledReference? debugOrigin]) → R -
Rebuilds a rebuildable provider (e.g. ViewProvider, FutureProvider)
and returns the result of the builder function.
override
-
redux<
N extends ReduxNotifier< (T> , T>ReduxProvider< N, T> provider) → Dispatcher<N, T> -
Get a proxy class to dispatch actions to a ReduxNotifier.
override
-
set(
ProviderOverride< BaseNotifier, dynamic> override) → FutureOr<void> - Overrides a provider with a new value. This allows for overrides happening after the container was created.
-
stream<
N extends BaseNotifier< (T> , T>ProviderAccessor< BaseProvider< provider, [void onInitNotifier(BaseProvider<N, T> , N, T>BaseNotifier, dynamic> , BaseNotifier)?]) → Stream<NotifierEvent< T> > -
Listen for changes to a provider.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited