WidgetRef vs BuildContext #4054
Unanswered
Disregard-Therest
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am really confused about the things I've found recently....
We all know that if you user BuildContext across async gap, you will get a warning from linter...
And we have context.mounted to prevent this.
But the problem is that WidgetRef is absolutely the same - if the context is lost, any call to ref provides the following error: "Bad state: Cannot use "ref" after the widget was disposed."
But there is no warning about this and no way I can check it before I call it...
And the most surprising thing for me is that WidgetRef is actually (context as WidgetRef) and any method of ref could be called via (context as WidgetRef).
So, the questions are:
Explanation...
I am coding libraries for my team and I have an extension on WidgetRef with useful things, but I don't want to have crushes whenever this extension is used after the context has been lost....
So I want to turn it into extension on BuildContext so that I will at least have linter tips on using BuildContext across async Gaps
Beta Was this translation helpful? Give feedback.
All reactions