Skip to content

UI Node key confusion #26

@cpu-chromium

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.

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