findFirstFocusInDirection method

  1. @override
FocusNode? findFirstFocusInDirection(
  1. FocusNode currentNode,
  2. TraversalDirection direction
)
override

Returns the first node in the given direction that should receive focus if there is no current focus in the scope to which the currentNode belongs.

This is typically used by inDirection to determine which node to focus if it is called when no node is currently focused.

Implementation

@override
FocusNode? findFirstFocusInDirection(FocusNode currentNode, TraversalDirection direction) {
  switch (direction) {
    case TraversalDirection.up:
      // Find the bottom-most node so we can go up from there.
      return _sortAndFindInitial(currentNode, vertical: true, first: false);
    case TraversalDirection.down:
      // Find the top-most node so we can go down from there.
      return _sortAndFindInitial(currentNode, vertical: true, first: true);
    case TraversalDirection.left:
      // Find the right-most node so we can go left from there.
      return _sortAndFindInitial(currentNode, vertical: false, first: false);
    case TraversalDirection.right:
      // Find the left-most node so we can go right from there.
      return _sortAndFindInitial(currentNode, vertical: false, first: true);
  }
}