Skip to content
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

Fix 'Null check operator used on a null value' #161

Merged
merged 1 commit into from
Jun 2, 2024

Conversation

lukehutch
Copy link

Gets rid of unchecked use of !...

The exception can be triggered on a hot reload, or probably in other situations too.

@jb3rndt
Copy link
Owner

jb3rndt commented May 26, 2024

Thank you. I am interested in which exact cases this problem occurs because this should never happen. Could you provide an example?

@lukehutch
Copy link
Author

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...

@jb3rndt jb3rndt merged commit 83eb147 into jb3rndt:master Jun 2, 2024
@jb3rndt
Copy link
Owner

jb3rndt commented Jun 2, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants