How to Periodically Refresh (Polling) API Using Riverpod in Flutter
ฝัง
- เผยแพร่เมื่อ 15 มิ.ย. 2024
- Learn how to easily periodically refresh API data automatically using the Riverpod state management library in Flutter. This tutorial covers setting up periodic refreshes, displaying loading indicators, and making your code more organized by using Dart extensions.
Substack: widgettricks.substack.com
Live Classes : effectiveflutterdev.com
Twitter: / burhanrashid52
LinkedIn: / burhanuddin-rashid
Instagram: / burhanrashid52
Website: burhanrashid52.com
Riverpod : riverpod.dev/docs/introductio...
Very Nice Video.
Thank you :)
it helped me a lot.
Thank you!
I am Glad it helped!
Can you also make a video on background processes? Like scheduling a task every 3 hours even if the app is closed or is in the background.
Background processes change rapidly based on the OS so its very hard to make video on it. You try pub.dev/packages/workmanager
Hello bro i need your help basically i am making my final year project and i am using flutter and for state management riverpod . But from 3 days i stuck in a problem i cannot able to implement pagination in my app with riverpod i tried so many things i dm so many devlopers but no one helping me i think you can help me in this basically the problem is same as you video but little bit different
It's very hard to provide any concrete solution for this. I would recommend creating a minimum reproducible code on either DartPad or GitHub repository, or asking on StackOverflow with all these details.
Read more here: stackoverflow.com/help/minimal-reproducible-example
I would think you'd want to cancel the timer on a dispose, otherwise it will try to act on an umounted context.
Initially, I thought the same, but in this case, where we are just using Timer.run(), then we don't need it because if the widget is not mounted, the ref is auto-disposed and the call to ref.invalidate() doesn't do anything.
ref.onDispose will be useful when we are using Timer.periodic for some other side effect rather than invalidateSelf().
@@codinglife52 Can you elaborate the major diff b/w Timer() and Timer.periodic(). Without using Annotation to generate the providers & basically, we deal with StateProvider for one-time actions and for runtime StateNotifierProvider classes we use. So how it can be different from having these from annotating the functions using @riverpod
@HemasaicharanK `Timer()` is just a one-time operation, whereas `Timer.periodic()` is periodic. The periodic one needs to be cleaned manually when the Riverpod provider is autodisposed. If we use just `Timer()`, the code won't execute if the provider is disposed.
Annotations are there to help you avoid boilerplate code for all providers. In your case, with `StateProvider` it will create the bolierplat code to setup `StateProvider` , you can achieve the same `ref.invalidate()` logic without using annotations.