previousElementSibling property Null safety

XmlElement? previousElementSibling

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

Implementation

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