This is an RFC (Request for Comments) for a proposed new, simplified syntax for defining providers and notifiers in the Riverpod state management framework for Flutter. It aims to reduce boilerplate and the need for code generation by using plain functions and slightly modified class definitions. The discussion has active engagement from the Riverpod community.
A starter prompt for Claude Code, what you'll need, and how to reach them.
You are an expert Flutter and Dart developer. Your task is to implement the proposed 'unified Provider syntax' as described in the rrousselGit/riverpod issue #4752. Focus on the core changes required for defining providers as plain functions that take a `Ref` argument (e.g., `Repository myRepositoryProvider(Ref ref) { return MyRepository(); }`) and the updated `Notifier/AsyncNotifier/StreamNotifier` class definitions where the provider is optionally defined as a constant (e.g., `const counterProvider = Counter.new;`).
Your implementation should be a proof-of-concept within a forked version of the Riverpod library, specifically targeting the `lib/src` directory for core changes and `example/` for a demonstration of the new API. Ensure the implementation handles various provider types (Provider, FutureProvider, StreamProvider, Notifier, AsyncNotifier, StreamNotifier). Write a simple example app in `example/` that showcases all these new syntaxes. The project uses Dart and Flutter. Prioritize clean, idiomatic Dart code and maintain consistency with Riverpod's existing coding style. Include necessary test cases to validate the new syntax. For the MVP, focus on the provider definition and a basic notifier, ensuring they compile and resolve dependencies correctly.Hello Riverpod community! I'd like to discuss a second take on the "Simplified Riverpod syntax without code-generation". This is similar to [#4008](https://github.com/rrousselGit/riverpod/issues/4008), but proposes an alternate syntax. Long story short: ## Defining a provider Providers would be defined as plain functions that take a `Ref` argument: ```dart // Equivalent of Provider<Repository> Repository myRepositoryProvider(Ref ref) { return MyRepository(); } // Equivalent of FutureProvider<User> Future<User> fetchUserProvider(Ref ref) { return http.get(...); } // Equivalent of StreamProvider<User> Stream<User> fetchUserProvider(Ref ref) { return firebase.auth... } ``` ## Notifiers There are two possible paths for Notifiers. 1. Stay as similar to today as possible: Use classes Notifiers would instead be classes that extend `Notifier/AsyncNotifier/StreamNotifier`, with an optionally defined constant next to the next ```dart class Counter extends Notifier<int> { // TODO override build as usual } const counterProvider = Counter.new; // Optional class TodoList extends AsyncNotifier<List<Todo>> { // TODO override build as usual } const todoListProvider = TodoList.new; // Op
Standard for open-source contributions.
Standard for Flutter development.
Requires reading Riverpod's existing source code and documentation – ~3-5 days of focused study.
Learn it: Search getting-started ↗
Add a detailed comment to the GitHub issue #4752, outlining your proposed implementation strategy and asking for feedback.
“I've reviewed the RFC for unified Provider syntax in #4752 and have a concrete plan to implement a proof-of-concept. I've already started exploring a fork and can deliver a working demo of the new `Ref` based functions and constant notifiers. Would you be open to a draft PR once I have something tangible?”
Open the original ↗