-
-
Notifications
You must be signed in to change notification settings - Fork 973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Keep Alive / Autodispose) Provider logic #3129
Comments
Consider instead creating an extension method on AutoDisposeRef extension AliveWhenServer<>T on AutoDisposeRef<T> {
void keepAliveForServer() {
KeepAliveLink? link;
listen(serverProvider, (_, next) {
if (next.isConnected) { // check that link isn't active?
link = keepAlive();
}
if (!next.isConnected) link?.close();
});
}
} |
@TekExplorer but that doesn't work for the case that KA consumer doesn't know his KA provider !? !? |
What does that even mean? If you need to pass family parameters (for example) pass them in as parameters. |
It is the case when the Consumer is in a package and the Provider is in the project. |
That is bad. Don't do that. Packages should not ever ask for a raw provider for any reason. That's what callbacks and normal values are for. |
Also, you're passing a ref into something. Don't do that. |
I'm not passing a |
Closing due @TekExplorer teach me about a solution with https://api.flutter.dev/flutter/widgets/IndexedStack-class.html. Thanks |
I created a (Keep Alive / Auto Dispose) Provider logic.
Semantics:
KA provider: Provides KA status to multiple KA consumers. (It is a non-disposable provider)
KA consumer: Consumes KA status from one KA provider. (it is a disposable consumer)
Why:
It is a repeated scenario to have providers which have to change its Keep Alive/Auto Dispose status.
Example: My App manages multiple servers. I want some providers to be alive while its server connection is alive.
I can have multiple server connections alive.
Code:
. KeepAliveProviderMixin
. KeepAliveConsumerMixin
How it works?
A KA provider must call
init()
on thebuild()
method.A KA consumer must call
init()
on thebuild()
method.When a server get dis/connected its KA provider status is updated (via Side Effect).
When a KA consumer knows its KA provider, it must supply it (
ProviderListenable<bool>
) ininit()
.When a KA consumer doesn't know its KA provider, it must call
updateProvider()
on any widget update.Complexity:
The easy scenario is when the KA provider is known by the KA consumers (the last are in the same or lower level in the project library chain).
A little bit more complex scenario is when the KA provider isn't known by KA consumers (E.G.. KA consumer is on a package library and KA provider is at project level).
This is resolved by passing the KA provider via Widget property. (**)
Questions:
(**) It works, but it is acceptable by the Riverpod "guidelines"?
Any help/comment/suggestion is appreciated.
keep_alive_provider.mixin.dart:
keep_alive_consumer.mixin.dart:
The text was updated successfully, but these errors were encountered: