xPosForChildWithWidth method

double xPosForChildWithWidth(
  1. double width,
  2. CrossAxisAlignment alignment,
  3. double minX,
  4. double maxX,
)

Given a child's width and alignment, and the minX and maxX, returns the x position for the child.

Implementation

double xPosForChildWithWidth(
    double width, CrossAxisAlignment alignment, double minX, double maxX) {
  final double childCrossPosition;
  switch (alignment) {
    case CrossAxisAlignment.start:
      childCrossPosition = isLTR ? minX : maxX - width;
      break;
    case CrossAxisAlignment.end:
      childCrossPosition = isRTL ? minX : maxX - width;
      break;
    case CrossAxisAlignment.center:
      childCrossPosition = (minX + maxX) / 2.0 - width / 2.0;
      break;
    case CrossAxisAlignment.stretch:
    case CrossAxisAlignment.baseline:
      childCrossPosition = minX;
      break;
  }
  return childCrossPosition;
}