debugThrowIfNotCheckingIntrinsics method

  1. @protected
bool debugThrowIfNotCheckingIntrinsics()

Throws an exception saying that the object does not support returning intrinsic dimensions if, in debug mode, we are not in the RenderObject.debugCheckingIntrinsics mode.

This is used by computeMinIntrinsicWidth et al because viewports do not generally support returning intrinsic dimensions. See the discussion at computeMinIntrinsicWidth.

Implementation

@protected
bool debugThrowIfNotCheckingIntrinsics() {
  assert(() {
    if (!RenderObject.debugCheckingIntrinsics) {
      assert(this is! RenderShrinkWrappingViewport); // it has its own message
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('$runtimeType does not support returning intrinsic dimensions.'),
        ErrorDescription(
          'Calculating the intrinsic dimensions would require instantiating every child of '
          'the viewport, which defeats the point of viewports being lazy.',
        ),
        ErrorHint(
          'If you are merely trying to shrink-wrap the viewport in the main axis direction, '
          'consider a RenderShrinkWrappingViewport render object (ShrinkWrappingViewport widget), '
          'which achieves that effect without implementing the intrinsic dimension API.',
        ),
      ]);
    }
    return true;
  }());
  return true;
}