text property Null safety

String? text

Returns all of the top-level text nodes found in children and returns them combined into a string.

Returns null if no text nodes exist.

Implementation

String? get text {
  if (children == null) return null;

  var text = '';

  for (var child in children!) {
    if (child is XmlText) {
      text += ((text.isEmpty) ? '' : ' ') + child.value;
    }
  }

  if (text.isEmpty) return null;

  return text;
}