call<M> method

Morphic call<M>([
  1. List<M>? children
])

Call operator for children

Implementation

Morphic call<M>([List<M>? children]) {
  // Void elements can't have children
  if (isVoid && children != null && children.isNotEmpty) {
    throw ArgumentError(
      '<$tag> is a void element and cannot have children. '
      'Use $tag() without arguments or $tag.attr() methods only.',
    );
  }

  final normalizedChildren = isVoid
      ? <Object>[]
      : MorphicChildren.normalize(children ?? []);

  final finalAttrs = <String, Attribute>{
    if (_classes != null) 'class': ClassAttribute(_classes!),
    if (_id != null) 'id': StringAttribute(_id!),
    if (_style != null) 'style': StyleAttribute(_style!),
    ..._attrs,
  };

  return ElementMorphic(
    tag: tag,
    key: key,
    attributes: finalAttrs,
    children: normalizedChildren,
  );
}