compareTo method Null safety

  1. @override
RenderComparison compareTo(
  1. InlineSpan other
)
override

Describe the difference between this span and another, in terms of how much damage it will make to the rendering. The comparison is deep.

Comparing InlineSpan objects of different types, for example, comparing a TextSpan to a WidgetSpan, always results in RenderComparison.layout.

See also:

Implementation

@override
RenderComparison compareTo(InlineSpan other) {
  if (identical(this, other)) {
    return RenderComparison.identical;
  }
  if (other.runtimeType != runtimeType) {
    return RenderComparison.layout;
  }
  final TextSpan textSpan = other as TextSpan;
  if (textSpan.text != text ||
      children?.length != textSpan.children?.length ||
      (style == null) != (textSpan.style == null)) {
    return RenderComparison.layout;
  }
  RenderComparison result = recognizer == textSpan.recognizer ?
    RenderComparison.identical :
    RenderComparison.metadata;
  if (style != null) {
    final RenderComparison candidate = style!.compareTo(textSpan.style!);
    if (candidate.index > result.index) {
      result = candidate;
    }
    if (result == RenderComparison.layout) {
      return result;
    }
  }
  if (children != null) {
    for (int index = 0; index < children!.length; index += 1) {
      final RenderComparison candidate = children![index].compareTo(textSpan.children![index]);
      if (candidate.index > result.index) {
        result = candidate;
      }
      if (result == RenderComparison.layout) {
        return result;
      }
    }
  }
  return result;
}