Skip to content

UI Node key confusion #26

Description

@cpu-chromium

UI nodes require a unique key for arrays of homogeneous children. They key is nominally Object but internally it seems to be converted to String. This causes the surprising behavior that custom objects are rejected as keys:

[0612/154234:ERROR:dart_error.cc(20)] Unhandled exception:
Uncaught Error: If multiple non-interchangeable nodes of the same type exist as children
of another node, they must have unique keys.
Duplicate:

The current workaround is to add a custom .toString() method to any custom class used as key

For example

class Cell {
final int posX;
final int posY;
Cell(this.posX, this.posY);
String toString() => 'Cell($posX, $posY)';
}

without the toString() method, it cannot be used as a key.

Activity

  1. abarth commented on Jun 13, 2015

    @abarth
    Contributor

    I spoke with hixie about this issue, and he thinks we should change the type for |key| to |String|.

  2. abarth commented on Jun 16, 2015

    @abarth
    Contributor
  3. added a commit that references this issue on Jul 16, 2015
  4. github-actions commented on Sep 7, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Sep 7, 2021
  6. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions