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

Contradictory comments for AsyncValue.value #3255

Closed
gmkado opened this issue Jan 5, 2024 · 2 comments
Closed

Contradictory comments for AsyncValue.value #3255

gmkado opened this issue Jan 5, 2024 · 2 comments

Comments

@gmkado
Copy link

gmkado commented Jan 5, 2024

Looking at the comments for AsyncValue.value says both "It will return the previous value during loading/error state" and "This will return null during loading/error states". These seem contradictory.

https://github.com/rrousselGit/riverpod/blob/11244e40a380147d1823ad6efc61b6cc3ec84d4b/packages/riverpod/lib/src/common.dart#L183C3-L194C57

@snapsl
Copy link

snapsl commented Jan 7, 2024

The comment is very descriptive. AsyncValue.value will return the previous value during loading/error state if a previous value exists.
If you do not want to to return the previous value during these states, use ref.watch(provider).unwrapPrevious().valueOrNull as stated in the comment.

@gmkado
Copy link
Author

gmkado commented Jan 7, 2024

Ah okay thanks @snapsl I read the comment wrong. I thought both of those lines pertained to value, but the last line is talking about the example in the code block.

@gmkado gmkado closed this as completed Jan 7, 2024
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

No branches or pull requests

2 participants