debugAssertIsValid method

bool debugAssertIsValid({
  1. InformationCollector? informationCollector,
})

Asserts that this geometry is internally consistent.

Does nothing if asserts are disabled. Always returns true.

Implementation

bool debugAssertIsValid({
  InformationCollector? informationCollector,
}) {
  assert(() {
    void verify(bool check, String summary, {List<DiagnosticsNode>? details}) {
      if (check) {
        return;
      }
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('${objectRuntimeType(this, 'SliverGeometry')} is not valid: $summary'),
        ...?details,
        if (informationCollector != null)
          ...informationCollector(),
      ]);
    }

    verify(scrollExtent >= 0.0, 'The "scrollExtent" is negative.');
    verify(paintExtent >= 0.0, 'The "paintExtent" is negative.');
    verify(layoutExtent >= 0.0, 'The "layoutExtent" is negative.');
    verify(cacheExtent >= 0.0, 'The "cacheExtent" is negative.');
    if (layoutExtent > paintExtent) {
      verify(false,
        'The "layoutExtent" exceeds the "paintExtent".',
        details: _debugCompareFloats('paintExtent', paintExtent, 'layoutExtent', layoutExtent),
      );
    }
    // If the paintExtent is slightly more than the maxPaintExtent, but the difference is still less
    // than precisionErrorTolerance, we will not throw the assert below.
    if (paintExtent - maxPaintExtent > precisionErrorTolerance) {
      verify(false,
        'The "maxPaintExtent" is less than the "paintExtent".',
        details:
          _debugCompareFloats('maxPaintExtent', maxPaintExtent, 'paintExtent', paintExtent)
            ..add(ErrorDescription("By definition, a sliver can't paint more than the maximum that it can paint!")),
      );
    }
    verify(hitTestExtent >= 0.0, 'The "hitTestExtent" is negative.');
    verify(scrollOffsetCorrection != 0.0, 'The "scrollOffsetCorrection" is zero.');
    return true;
  }());
  return true;
}