I'm learning Riverpod as a library for keeping global state in my application.
In previous applications I've built I had a class that wraps an http client (either http or DIO) - it's a wrapper so if I choose to replace it I only need to change that class implementation and all the application would still be working without any change.
The I have other classes that represent my API and uses that wrapper to make calls (for instance: UsersApi
, PostsApi
, etc), cache the data locally and handle any conversions needed by my client application.
Managing state between widgets was by passing callbacks or using ChangeNotifier
(leading to callback hell) - this is why I'm looking for a global state manager solution.
I've seen some tutorials on YouTube and read the following:
https://towardsdev.com/using-riverpod-future-provider-to-fetch-api-7706cad3718e
https://riverpod.dev/docs/essentials/first_request
https://riverpod.dev/docs/essentials/side_effects
With Riverpod, each such API call that I have to my server should now be a provider. That means that every such API call (function) that I previously had in my classes should now be a Provider
on the global scope? or should I do some hybrid approach where some calls are using Providers and some aren't?
Also, I see there is a difference if I create the Providers myself or using the annotations and let the build script build them for me - what's the better approach?