nextElementSibling property Null safety

XmlElement? nextElementSibling

Return the next element sibling of this node, or null.

Implementation

XmlElement? get nextElementSibling {
  if (parent != null) {
    final siblings = parent!.children;
    for (var i = 0; i < siblings.length - 1; i++) {
      if (identical(siblings[i], this)) {
        for (var j = i + 1; j < siblings.length; j++) {
          final candidate = siblings[j];
          if (candidate is XmlElement) {
            return candidate;
          }
        }
        return null;
      }
    }
  }
  return null;
}