Skip to content

ValueNotifier documentation blurs the line between equality and identity #142418

@RandalSchwartz

Description

@RandalSchwartz

Steps to reproduce

In the docs for ValueNotifier, we see:

/// Because this class only notifies listeners when the [value]'s identity
/// changes, listeners will not be notified when mutable state within the
/// value itself changes.

But in fact, if you check the code, it calls ==, not identical() so it will in fact notify if an overridden equality reports false.
The docs go on to blur this by using List, which does an identity check for equality, and is thus a common but bad example.

The docs could be updated to show that == is being used, and will properly use a deeper equality test if the object class provides it.

Expected results

Reader is informed, and can properly infer the behavior looking only at the documentation.

Actual results

Reader is confused, and must dig into the source code to explain a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectd: api docsIssues with https://api.flutter.dev/d: examplesSample code and demosframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions