sortDescendants method Null safety

  1. @protected
Iterable<FocusNode> sortDescendants(
  1. Iterable<FocusNode> descendants,
  2. FocusNode currentNode
)
protected">@protected

Sorts the given descendants into focus order.

Subclasses should override this to implement a different sort for next and previous to use in their ordering. If the returned iterable omits a node that is a descendant of the given scope, then the user will be unable to use next/previous keyboard traversal to reach that node.

The node used to initiate the traversal (the one passed to next or previous) is passed as currentNode.

Having the current node in the list is what allows the algorithm to determine which nodes are adjacent to the current node. If the currentNode is removed from the list, then the focus will be unchanged when next or previous are called, and they will return false.

This is not used for directional focus (inDirection), only for determining the focus order for next and previous.

When implementing an override for this function, be sure to use mergeSort instead of Dart's default list sorting algorithm when sorting items, since the default algorithm is not stable (items deemed to be equal can appear in arbitrary order, and change positions between sorts), whereas mergeSort is stable.

Implementation

@protected
Iterable<FocusNode> sortDescendants(Iterable<FocusNode> descendants, FocusNode currentNode);