testSize method

void testSize(
  1. TargetId targetId,
  2. Size targetSize,
  3. SizeAssert assertion
)

Tests the size of the provided widget.

The size of the widget is provided as targetSize.

Implementation

void testSize(
  TargetId targetId,
  Size targetSize,
  SizeAssert assertion,
) {
  final width = assertion.width;
  DoublePair? widthFail;
  if (width != null && width != targetSize.width) {
    widthFail = DoublePair(targetSize.width, width);
  }

  final height = assertion.height;
  DoublePair? heightFail;
  if (height != null && height != targetSize.height) {
    heightFail = DoublePair(targetSize.height, height);
  }

  if (atLeastOne([widthFail, heightFail])) {
    throw AssertionFailedException.forSize(
      targetId: targetId,
      width: widthFail,
      height: heightFail,
    );
  }
}