Skip to content

Surprising behavior of ValueNotifier (doesn't notify on certain changes) #29922

@ravenblackx

Description

@ravenblackx

ValueNotifier, for example, doesn't notify in the case that

SomeProto a = new SomeProto();
a.setSomeInt(5);
SomeProto b = new SomeProto();
b.setSomeInt(5);
valueNotifier_ = a;  // listeners are notified.
valueNotifier_ = b;  // listeners are not notified.

The cause of this surprising behavior is that ValueNotifier uses the == operator of the contained object to determine whether the value has changed.

The description of ValueNotifier says "When the value is replaced, this class notifies its listeners", which suggests that this is not the intended behavior in this case (and, indeed, if the notifier were supposed to be triggered only on inner content changing then the current behavior also fails at that, since

valueNotifier_ = a;
a.setSomeInt(6);

would not provoke a notification.)

I have a patch that fixes this and adds a test, will make a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    d: stackoverflowGood question for Stack Overflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions