Closed lukehutch closed 1 month ago
Thank you. I am interested in which exact cases this problem occurs because this should never happen. Could you provide an example?
As I mentioned hot reload triggered this for me. However, I think the issue was also triggered when I was trying to dynamically change the number of tabs (discussed in another issue).
The general rule here though is that you can never assume that a Key
's currentState
is non-null, since that state can be torn down anytime the widget is disposed. In particular though, you can't assume that currentState
is going to be available if an onTap
handler or similar is interrupted by an awaited async call.
Similarly, you should never call setState
unless you first check if the widget is still mounted
, if you know that there is any chance there is an await
somewhere between an event handler call and the setState
call.
When developing libraries, you can't assume everyone is going to call your methods in the same orthodox way you would call them yourself, so you have to protect against this sort of issue...
When developing libraries, you can't assume everyone is going to call your methods in the same orthodox way you would call them yourself, so you have to protect against this sort of issue...
Sure, thats why I try to understand that "unintended" way of using the lib because that might have effects on other parts too. But I agree this can have many reasons in this case so an example might not be very useful...
Thanks for catching this!
Gets rid of unchecked use of
!
...The exception can be triggered on a hot reload, or probably in other situations too.