debugAssertIsValid method

  1. @override
bool debugAssertIsValid ({bool isAppliedConstraint: false, InformationCollector informationCollector })
override

Asserts that the constraints are valid.

This might involve checks more detailed than isNormalized.

For example, the BoxConstraints subclass verifies that the constraints are not double.nan.

If the isAppliedConstraint argument is true, then even stricter rules are enforced. This argument is set to true when checking constraints that are about to be applied to a RenderObject during layout, as opposed to constraints that may be further affected by other constraints. For example, the asserts for verifying the validity of RenderConstrainedBox.additionalConstraints do not set this argument, but the asserts for verifying the argument passed to the RenderObject.layout method do.

The informationCollector argument takes an optional callback which is called when an exception is to be thrown. The collected information is then included in the message after the error line.

Returns the same as isNormalized if asserts are disabled.

Implementation

@override
bool debugAssertIsValid({
  bool isAppliedConstraint = false,
  InformationCollector informationCollector,
}) {
  assert(() {
    void verify(bool check, String message) {
      if (check)
        return;
      final StringBuffer information = StringBuffer();
      if (informationCollector != null)
        informationCollector(information);
      throw FlutterError('$runtimeType is not valid: $message\n${information}The offending constraints were:\n  $this');
    }
    verify(axis != null, 'The "axis" is null.');
    verify(growthDirection != null, 'The "growthDirection" is null.');
    verify(scrollOffset != null, 'The "scrollOffset" is null.');
    verify(overlap != null, 'The "overlap" is null.');
    verify(remainingPaintExtent != null, 'The "remainingPaintExtent" is null.');
    verify(crossAxisExtent != null, 'The "crossAxisExtent" is null.');
    verify(viewportMainAxisExtent != null, 'The "viewportMainAxisExtent" is null.');
    verify(scrollOffset >= 0.0, 'The "scrollOffset" is negative.');
    verify(crossAxisExtent >= 0.0, 'The "crossAxisExtent" is negative.');
    verify(crossAxisDirection != null, 'The "crossAxisDirection" is null.');
    verify(axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection), 'The "axisDirection" and the "crossAxisDirection" are along the same axis.');
    verify(viewportMainAxisExtent >= 0.0, 'The "viewportMainAxisExtent" is negative.');
    verify(remainingPaintExtent >= 0.0, 'The "remainingPaintExtent" is negative.');
    verify(remainingCacheExtent >= 0.0, 'The "remainingCacheExtent" is negative.');
    verify(cacheOrigin <= 0.0, 'The "cacheOrigin" is positive.');
    verify(isNormalized, 'The constraints are not normalized.'); // should be redundant with earlier checks
    return true;
  }());
  return true;
}