-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: extend use_build_context_synchronously to consider Riverpod's WidgetRef #58744
Comments
The current rule says
Does the same apply for |
Yes, this applies to WidgetRef too. |
It's probably worth noting that WidgetRef is a class that interacts with BuildContext (hence why the rules should be respected) Such that we have: abstract class WidgetRef {
void doSomething() {
Object.of(context).doSomething();
}
} So maybe what makes sense would be to annotate the functions of WidgetRef, not WidgetRef itself. Maybe something like abstract class WidgetRef {
@useBuildContext
void doSomething();
} |
Definitely worth considering. Would this be useful for other users? I don't know Flutter well enough to know whether users might write methods similar to |
It's probably not very common. Most cases would end-up passing the The case described here is different because it already has access to the context, so passing it is redundant |
CC @goderbauer any strong opinion? |
For what it's worth, I'm working on riverpod-specific lint-rules using analyzer_plugin So I could implement this on my own if necessary. Although the annotation approach here would make my like a lot easier |
@rrousselGit Another use case would be the @bwilkerson Perhaps we can generalize the rule to a
|
I'd like to get some input from the Flutter team before making a decision, but I'd much rather see us define an annotation that can be used outside of Flutter rather than implement some special case logic. |
I agree, having the |
Hello! I'm not sure whether this is reasonable, but it's worth asking.
Long story short, Riverpod would like to define a lint strictly identical to
use_build_context_synchronously
but for itsWidgetRef
object.The lint would be identical in every point, such that BuildContext/WidgetRef can constantly be interchanged. As a matter of fact, WidgetRef is a BuildContext. It uses a different interface to cause less confusion and allows folks using package:provider to smoothly migrate to package:riverpod.
As such, would it be reasonable to update use_build_context_synchronously to handle Riverpod's WidgetRef too?
Such that we have:
I understand that this repository probably wants to be clean of third-party package logic.
If necessary, maybe a solution could be to add a custom package:meta annotation that both WidgetRef and BuildContext would use (
@shouldUseSynchronously
or@isBuildContext
?)The text was updated successfully, but these errors were encountered: