toElements method

List<T>? toElements(
  1. Object? elements
)

Implementation

List<T>? toElements(Object? elements) {
  if (elements == null) {
    return null;
  } else if (elements is T) {
    return [elements as T];
  } else if (elements is DOMNode) {
    var e = generate(elements);
    if (e == null) {
      throw StateError("Can't generate element for `DOMNode`: $elements");
    }
    return [e];
  } else if (elements is String) {
    var e = generateFromHTML(elements);
    if (e == null) {
      throw StateError("Can't generate element from `HTML`: $elements");
    }
    return [e];
  } else if (elements is Function) {
    var e = elements();
    return toElements(e);
  } else if (elements is Iterable) {
    return elements
        .expand((e) => toElements(e)!)
        .where((e) => e != null)
        .toList();
  } else {
    return null;
  }
}