debugDescribeInvalidAncestorChain method

Iterable<DiagnosticsNode> debugDescribeInvalidAncestorChain ({String description, DiagnosticsNode ownershipChain, bool foundValidAncestor, Iterable<Widget> badAncestors })

Subclasses should override this to describe the requirements for using the ParentDataWidget subclass. It is called when debugIsValidAncestor() returned false for an ancestor, or when there are extraneous ParentDataWidgets in the ancestor chain.

Implementation

Iterable<DiagnosticsNode> debugDescribeInvalidAncestorChain({ String description, DiagnosticsNode ownershipChain, bool foundValidAncestor, Iterable<Widget> badAncestors }) sync* {
  assert(T != dynamic);
  assert(T != RenderObjectWidget);
  if (!foundValidAncestor) {
    yield ErrorDescription(
      '$runtimeType widgets must be placed inside $T widgets.\n'
      '$description has no $T ancestor at all.'
    );
  } else {
    assert(badAncestors.isNotEmpty);
    yield ErrorDescription(
      '$runtimeType widgets must be placed directly inside $T widgets.\n'
      '$description has a $T ancestor, but there are other widgets between them:'
    );
    for (Widget ancestor in badAncestors) {
      if (ancestor.runtimeType == runtimeType) {
        yield ErrorDescription('- $ancestor (this is a different $runtimeType than the one with the problem)');
      } else {
        yield ErrorDescription('- $ancestor');
      }
    }
    yield ErrorDescription('These widgets cannot come between a $runtimeType and its $T.');
  }
  yield ErrorDescription('The ownership chain for the parent of the offending $runtimeType was:\n  $ownershipChain');
}