ForEachNode<T> class

List rendering primitive. Re-reads items reactively; each item is mapped through builder to a descriptor.

DOM Mounting and Reconciliation

In the browser, ForEachNode mounts between sentinel comments: <!-- bloom:foreach --> and <!-- /bloom:foreach -->.

  • Keyed lists (keyFn != null): Fine-grained list reconciliation. Each item is identified by the unique string returned from keyFn. When items updates, existing DOM nodes and reactive sub-regions for unchanged keys are retained and repositioned, new keys are mounted, and removed keys are disposed. This preserves input focus, text selection, and internal state.
  • Unkeyed lists (keyFn == null): When items updates, all existing child regions between the sentinels are disposed and rebuilt from scratch. The per-item reactive regions and their effects are dropped with them, so input focus, text selection, local DOM state, and in-flight CSS animations inside list items do not survive an update — even when items were merely appended or reordered. Pass keyFn for any list that can reorder, insert, or remove items.

SSR Behavior

During SSR (renderToHtml), items is called once synchronously and each item is mapped via builder to render the child nodes in order.

Usually created using the DSL sugar ForEach.

Inheritance

Constructors

ForEachNode(List<T> items(), BloomNode builder(T item), {String keyFn(T item)?})
Creates a list rendering descriptor with items, builder, and optional keyFn.
const

Properties

builder BloomNode Function(T item)
Factory callback mapping each item of type T to its BloomNode descriptor.
final
builderErased BloomNode Function(Object? value)
builder, accepting an untyped item Object?.
no setter
hashCode int
The hash code for this object.
no setterinherited
items List<T> Function()
Reactive getter returning the list of items to render.
final
itemsErased List<Object?> Function()
items, viewed as an untyped list getter List<Object?> Function().
no setter
keyFn String Function(T item)?
Optional key extractor function returning a unique string identifier for item.
final
keyFnErased String Function(Object? item)?
keyFn, accepting an untyped item Object?. Returns null when the list is unkeyed.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

buildChildren() List<BloomNode>
Synchronously evaluates items and maps each element through builder.
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