getAxisDirectionFromAxisReverseAndDirectionality function

AxisDirection getAxisDirectionFromAxisReverseAndDirectionality(
  1. BuildContext context,
  2. Axis axis,
  3. bool reverse
)

Returns the AxisDirection in the given Axis in the current Directionality (or the reverse if reverse is true).

If axis is Axis.vertical, this function returns AxisDirection.down unless reverse is true, in which case this function returns AxisDirection.up.

If axis is Axis.horizontal, this function checks the current Directionality. If the current Directionality is right-to-left, then this function returns AxisDirection.left (unless reverse is true, in which case it returns AxisDirection.right). Similarly, if the current Directionality is left-to-right, then this function returns AxisDirection.right (unless reverse is true, in which case it returns AxisDirection.left).

This function is used by a number of scrolling widgets (e.g., ListView, GridView, PageView, and SingleChildScrollView) as well as ListBody to translate their Axis and reverse properties into a concrete AxisDirection.

Implementation

AxisDirection getAxisDirectionFromAxisReverseAndDirectionality(
  BuildContext context,
  Axis axis,
  bool reverse,
) {
  switch (axis) {
    case Axis.horizontal:
      assert(debugCheckHasDirectionality(context));
      final TextDirection textDirection = Directionality.of(context);
      final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection);
      return reverse ? flipAxisDirection(axisDirection) : axisDirection;
    case Axis.vertical:
      return reverse ? AxisDirection.up : AxisDirection.down;
  }
}