SemanticsSortKey class

Base class for all sort keys for Semantics accessibility traversal order sorting.

Only keys of the same type and having matching names are compared. If a list of sibling SemanticsNodes contains keys that are not comparable with each other the list is first sorted using the default sorting algorithm. Then the nodes are broken down into groups by moving comparable nodes towards the earliest node in the group. Finally each group is sorted by sort key and the resulting list is made by concatenating the sorted groups back.

For example, let's take nodes (C, D, B, E, A, F). Let's assign node A key 1, node B key 2, node C key 3. Let's also assume that the default sort order leaves the original list intact. Because nodes A, B, and C, have comparable sort key, they will form a group by pulling all nodes towards the earliest node, which is C. The result is group (C, B, A). The remaining nodes D, E, F, form a second group with sort key being null. The first group is sorted using their sort keys becoming (A, B, C). The second group is left as is because it does not specify sort keys. Then we concatenate the two groups - (A, B, C) and (D, E, F) - into the final (A, B, C, D, E, F).

Because of the complexity introduced by incomparable sort keys among sibling nodes, it is recommended to either use comparable keys for all nodes, or use null for all of them, leaving the sort order to the default algorithm.

See Also:

  • SemanticsSortOrder which manages a list of sort keys.
  • OrdinalSortKey for a sort key that sorts using an ordinal.
Implemented by


SemanticsSortKey({String name })
Abstract const constructor. This constructor enables subclasses to provide const constructors so that they can be used in const expressions.


name String
An optional name that will make this sort key only order itself with respect to other sort keys of the same name, as long as they are of the same runtimeType.
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


compareTo(SemanticsSortKey other) int
Compares this object to another Comparable [...]
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
doCompare(SemanticsSortKey other) int
The implementation of compareTo. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
@pragma('vm:entry-point'), inherited
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by toStringDeep. [...]
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this object.
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode. [...]


operator ==(dynamic other) bool
The equality operator. [...]