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...

ความคิดเห็น • 12

  • @shreebhagwat1009
    @shreebhagwat1009 3 หลายเดือนก่อน +1

    Very Nice Video.

    • @codinglife52
      @codinglife52  3 หลายเดือนก่อน

      Thank you :)

  • @roninspect4357
    @roninspect4357 2 หลายเดือนก่อน +1

    it helped me a lot.
    Thank you!

    • @codinglife52
      @codinglife52  2 หลายเดือนก่อน

      I am Glad it helped!

  • @salahuddinshaikh7847
    @salahuddinshaikh7847 3 หลายเดือนก่อน +1

    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.

    • @codinglife52
      @codinglife52  3 หลายเดือนก่อน

      Background processes change rapidly based on the OS so its very hard to make video on it. You try pub.dev/packages/workmanager

  • @arunkashyap3527
    @arunkashyap3527 2 หลายเดือนก่อน

    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

    • @codinglife52
      @codinglife52  2 หลายเดือนก่อน

      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

  • @RandalLSchwartz
    @RandalLSchwartz 3 หลายเดือนก่อน

    I would think you'd want to cancel the timer on a dispose, otherwise it will try to act on an umounted context.

    • @codinglife52
      @codinglife52  2 หลายเดือนก่อน

      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().

    • @HemasaicharanK
      @HemasaicharanK 2 หลายเดือนก่อน

      @@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

    • @codinglife52
      @codinglife52  2 หลายเดือนก่อน

      @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.