invalidate method
Invalidates the state of the provider, destroying the state immediately and causing the provider to rebuild at some point in the future.
As opposed to refresh, the rebuild is not immediate and is instead delayed by an undefined amount of time. Typically, the rebuild happens at the next tick of the event loop. But if a provider is not listened to, the rebuild may be delayed until the provider is listened to again.
Calling invalidate multiple times will refresh the provider only once. Calling invalidate will cause the provider to be disposed immediately.
asReload
(false by default) can be optionally passed to tell Riverpod to clear the state before refreshing it. This is only useful for asynchronous providers, as by default, AsyncValue keeps a reference on state during loading states. UsingasReload
will disable this behavior and count as a "hard refresh".
If used on a provider which is not initialized or disposed, this method will have no effect.
Implementation
void invalidate(ProviderOrFamily provider, {bool asReload = false}) {
switch (provider) {
case $ProviderBaseImpl<Object?>():
_pointerManager
.readElement(provider)
?.invalidateSelf(asReload: asReload);
case Family():
for (final element in _pointerManager.listFamily(provider)) {
element.invalidateSelf(asReload: asReload);
}
}
}