This repo contains a simple example on how to use Riverpod when Clean Architecture is a requirement.
For some weird reason, We've seen a trend involving lots of threads and discussions on several platforms (Discord, SO, Twitter, Reddit), in which Riverpod is mentioned as being somewhat "hard", "messy" and / or only suitable for very simple projects (or for experts only, at scale). We've also seen a lot of architecture discussions, often mentioning buzzwords such as mvc, mvvm, mvp, mvw (etc.) in which Riverpod is placed as "used for its controllers only", as opposed to BLoC's strong "Clean Architecture"-like capability.
Nothing is further from the truth. When used properly, Riverpod is simple to reason with, simple to start with, and scales incredibly well, with nearly zero overhead. Plus, it offers incredibly simple and flexible caching features.
Riverpod is a complete replacement implementation for the Dependency Injection pattern, while also being a reactive caching and data-binding framework. That's it, that's Riverpod.
If you're using Riverpod, chances are you won't use GetIt or any other service provier / injectors.
Thus, every service is always provided with its ad-hoc Provider
. At the same time, injecting is trivial: just use ref.watch
.
We are not "clean-architecture-nazis", and instead we always look at cleanliness with a pinch of pragmatism. In this example we never created interfaces, nor it felt "mandatory" to create repositories for every single external integration. Nonetheless, we still follow the main guidelines: there are the infamous three layers and each class / file / method / variable aims to have one, single, and easy to understand responsibility.
Our objective was to outline Riverpod's capability in a non-trivial context, while still keeping the requirements as simple as possible
This project uses this free (registration needed) Weather API. It is required to attach an API key at the requests.
I haven't set up (yet) a .env
importer for this project.
Thus, just go to dio.dart and substitute <your-api-key>
with your actual key (PLEASE, REMEMBER, DO NOT COMMIT THAT FILE).
- Add a .env importer or use another secret-hiding shanenigan
- Add i18n with slang
- Add more routes or get more creative when we've got some time (suggestions welcome)
We strongly encourage to reach us out via Github's issues. PRs are welcome, just open an issue first so that we know what problem you want to address.