Closed pattobrien closed 2 years ago
Hello!
You're asking for something that's not possible. The issue is Dart itself. There's not much state_notifer/Riverpod can do about it.
@rrousselGit I figured that might be the case... Thanks for the quick feedback.
Problem Description
When declaring a provider, it becomes rather tedious and somewhat illegible to explicitly define types for StateNotifierProvider.
For example, instead of being able to write:
we instead need to write:
For context, the mid-complexity app that I've begun migrating fully to Riverpod (for all layers) has ~70 declared providers. In the context of such apps, it becomes especially tedious to explicitly define types for the reasons stated below:
Declaration Length
Likelihood of Forgotten Generic Typing
Desired Solution
The desired solution is that the same line as above properly infers the State object of the StateNotifierProvider definition via the generic type of the StateNotifier in the return function (currently, only the StateNotifier type is inferred).
Possible Alternatives
I believe tooling (such as snippets or analyzer/lint rules) would help somewhat, but the DX would not be as great as if the types were inferred directly from the StateNotifierProvider class.