Skip to content

Can I use state = AsyncData(state.value!.copyWith(newState)); to update state? #3474

Discussion options

You must be logged in to vote

What may not be safe?
If your concern is that state.value may be null, you can just use state methods to test that and update your state accordingly.
If you use this code in response to user interaction, then you know whether this interaction is possible only when the state is loaded, and in this case you can just use state.requireValue (this avoid the !).
Also inspect the API of AsyncValue, there are many interesting methods in there.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by phamquoctrongnta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants