debugDescribeInvalidAncestorChain method

String debugDescribeInvalidAncestorChain ({String description, String 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

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