debugValidateChild method

bool debugValidateChild(
  1. RenderObject child
)

Checks whether the given render object has the correct runtimeType to be a child of this render object.

Does nothing if assertions are disabled.

Always returns true.

Implementation

bool debugValidateChild(RenderObject child) {
  assert(() {
    if (child is! ChildType) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary(
          'A $runtimeType expected a child of type $ChildType but received a '
          'child of type ${child.runtimeType}.',
        ),
        ErrorDescription(
          'RenderObjects expect specific types of children because they '
          'coordinate with their children during layout and paint. For '
          'example, a RenderSliver cannot be the child of a RenderBox because '
          'a RenderSliver does not understand the RenderBox layout protocol.',
        ),
        ErrorSpacer(),
        DiagnosticsProperty<Object?>(
          'The $runtimeType that expected a $ChildType child was created by',
          debugCreator,
          style: DiagnosticsTreeStyle.errorProperty,
        ),
        ErrorSpacer(),
        DiagnosticsProperty<Object?>(
          'The ${child.runtimeType} that did not match the expected child type '
          'was created by',
          child.debugCreator,
          style: DiagnosticsTreeStyle.errorProperty,
        ),
      ]);
    }
    return true;
  }());
  return true;
}