ForEach<T> class

Reactive list rendering sugar.

Renders a dynamic list of items. When key is supplied, enables fine-grained DOM reconciliation, reusing elements for unchanged keys and only updating insertions, deletions, and moves.

Keyless Tradeoff

Without key, every list update disposes and rebuilds the entire list region: the per-item reactive regions and effects are dropped, so input focus, text selection, local DOM state, and CSS animations inside items are lost on every update. Always pass key for any list that can reorder, insert, or remove items.

DOM Representation

Mounts between sentinel comments <!-- bloom:foreach --> and <!-- /bloom:foreach -->.

class Todo {
  final String id;
  final String title;
  Todo(this.id, this.title);
}

final todos = signal<List<Todo>>([
  Todo('1', 'Buy milk'),
  Todo('2', 'Write tests'),
]);

BloomNode todoList() => Ul(
  children: [
    ForEach<Todo>(
      () => todos.value,
      (item) => Li(
        key: item.id,
        text: item.title,
      ),
      key: (item) => item.id,
    ),
  ],
);
Inheritance

Constructors

ForEach(List<T> items(), BloomNode builder(T item), {String key(T item)?})
Creates a reactive list descriptor with items, builder, and optional key extractor.
const

Properties

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