-
-
Notifications
You must be signed in to change notification settings - Fork 960
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
(repurposed) Document that invalidate() may not cause a refresh if the provider isn't listened. #3773
Comments
my requirement is such that i want to passively listen for mySessionProvider and when its updated, want to refresh this profileStatsInfoProvider only after 1 second. |
Th refresh only happens if the provider is listened. From your code, it is unclear if your provider is listened or not. So I'll assume it isn't and that the behavior is expected. |
thanks so much for replying so quickly 🙏🏻 class MiracleApp extends HookConsumerWidget {
const MiracleApp({super.key});
void initializeCoreDataProviders(WidgetRef ref) {
ref.read(userStatsSummaryProvider);
ref.read(meditationSelectorProvider);
ref.read(profileStatsInfoProvider);
}
@override
Widget build(BuildContext context, WidgetRef ref) {
useEffect(() {
initializeCoreDataProviders(ref);
}, const []);
return MaterialApp.router(
title: 'My App',
routerConfig: appRouter,
);
}
} in the above example, i'm initializing some core providers which i will be listening to in some other screens at later point in time but i want the data in these providers ready and loaded without getting disposed off. 2 Questions here :
how do i do this ? |
i thought only AutoDisposeProviders get disposed off when there are no listeners, how do i get the always alive behavior ? do i have to use AutoDisposeProvider and then explicitly call ref.keepAlive( ) for this behavior ? seems little counter intuitive just to keep the provider alive. :thi |
Just switch read to something else that listens to the provider. So either watch or listen. It's up to you. |
here's my question : if AutoDisableProvider is supposed to get auto disposed and there's a way to keep it alive even when there are no listeners by calling ref.keepAlive() By using a Provider directly (which suggests that it won't auto dispose) , i would expect the provider to be kept alive even if there are no listeners. Or at least there should be a way to keep it alive. If i want this behavior, then using AutoDisposableProvider seems to be counter intuitive. What do u think ? |
I do not understand your question unfortunately |
ok , so i had a misunderstanding that calling ref.keepAlive( ) will ensure it will re-build right away after invalidating even when there are no listeners. that's why was asking questions related to ref.keepAlive for an auto dispose provider. pls ignore that. I think the doc in the code comments need to be updated : for
|
Describe the bug
ref.invalidateSelf is not triggering a refresh (read) but documentation says that invalidateSelf will refresh the provider.
To Reproduce
When mySessionProvider updates :
I only see log which says : "invalidated self" , but after this, i don't see "reading provider" log.
Expected behavior :
both "invalidated self" followed by "reading provider" should get logged
The text was updated successfully, but these errors were encountered: