Listener not triggered when updating nested object that is initially null #4221
ayyoub-coder
started this conversation in
General
Replies: 2 comments 1 reply
-
This should work. Please verify that your state is immutable. Also check that the state after you use "copyWith" does contain an user object and is not null. |
Beta Was this translation helpful? Give feedback.
0 replies
-
If |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
When a provider’s field is nullable and starts as null, calling copyWith on that field does not trigger ref.listen / ref.watch for a .select on that field—even though the controller calls state = state.copyWith(...).
Steps:
userProfile is null at start.
Controller updates only username via state.copyWith(userProfile: state.userProfile?.copyWith(username: 'Bob')).
Because state.userProfile is still null, Riverpod sees “previous == next” and skips the listener.
UI never updates.
Expected: the listener fires whenever any nested field changes, even if the object was previously null.
Beta Was this translation helpful? Give feedback.
All reactions