Fragment class final

A grouping element that renders no DOM node.

Fragment follows the same fluent call() API as every other ElementBuilder in Pulsar — but instead of producing an ElementMorphic with a tag, it produces a FragmentMorphic whose children are inserted directly as siblings into the parent DOM node.

This makes Fragment the correct tool whenever you need to return multiple nodes from a getter or conditional without adding a wrapper element to the HTML output.

Usage

// In a getter — multiple siblings without a wrapper div
Morphic get actions => Fragment()([
  Button().onClick(save)(['Save']),
  Button().onClick(cancel)(['Cancel']),
]);

// In render() with a conditional
@override
Morphic render() => Div()([
  H1()(['Title']),
  if (isExpanded) details,  // details is a Fragment
]);

What Fragment is NOT

Fragment is not a performance optimization. It is a structural tool. Use it when the absence of a wrapper element is semantically meaningful (e.g. inside a <ul> where only <li> children are valid, or inside a flex container where an extra div would break layout).

If a wrapper element is acceptable, prefer a plain Div or Span.

Constructors

Fragment({Object? key})
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key Object?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call([List? children]) FragmentMorphic
Produces a FragmentMorphic containing children.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited