ForEachStore<ID, GlobalState, GlobalAction, ItemState, ItemAction> class

A widget that renders each element of a collection with its own scoped Store.

Each item gets a scoped store derived from the parent store. Items are cached by ID for performance - only new items trigger widget creation. Removed items have their cached widgets cleaned up automatically.

Constructors

Example

ForEachStore.id(
  store: store,
  getIterable: (state) => state.contacts,
  embedAction: (id, action) => AppAction.contact(id, action),
  toID: (contact) => contact.id,
  iterableBuilder: IterableBuilder.listViewBuilder(),
  builder: (context, contactStore, id) =>
    ContactCard(store: contactStore),
);

See also:

Inheritance

Properties

builder → Widget Function(BuildContext context, Store<ItemState, ItemAction> store, ID id, int index, int itemCount)
Builder function called for each item.
final
embedAction → GlobalAction Function(ID id, ItemAction localAction)
Embeds a local item action into the global action type.
final
getIterable → Iterable<ItemState> Function(GlobalState state)
Extracts the iterable collection from the global state.
final
hashCode → int
The hash code for this object.
no setterinherited
iterableBuilder → Widget Function({required Widget? itemBuilder(BuildContext, int), int? itemCount})
Factory that creates the layout widget (e.g., ListView, Column).
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onEmptyBuilder → Widget Function(BuildContext)?
Builder shown when the collection is empty. If null, an empty Container is rendered.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
store → Store<GlobalState, GlobalAction>
The parent store containing the collection state.
final
toID → ID Function(int index, ItemState state)
Extracts a unique ID from an item and its index.
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
populateCache(BuildContext context, Iterable<ItemState> items) → void
Builds and caches widgets for any new items not yet in the cache.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

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

Static Methods

id<ID, GlobalState, GlobalAction, ItemState, ItemAction>({required Widget builder(BuildContext context, Store<ItemState, ItemAction> store, ID id), required Store<GlobalState, GlobalAction> store, required Iterable<ItemState> getIterable(GlobalState state), required GlobalAction embedAction(ID id, ItemAction localAction), required ID toID(ItemState state), required Widget iterableBuilder({required Widget? itemBuilder(BuildContext, int), int? itemCount}), Widget onEmptyBuilder(BuildContext)?}) → ForEachStore<ID, GlobalState, GlobalAction, ItemState, ItemAction>
Creates a ForEachStore that identifies items by a custom toID function.
indexed<GlobalState, GlobalAction, ItemState, ItemAction>({required Widget builder(BuildContext context, Store<ItemState, ItemAction> store, int index, int itemCount), required Store<GlobalState, GlobalAction> store, required Iterable<ItemState> getIterable(GlobalState state), required GlobalAction embedAction(int index, ItemAction localAction), required Widget iterableBuilder({required Widget? itemBuilder(BuildContext, int), int? itemCount}), Widget onEmptyBuilder(BuildContext)?}) → ForEachStore<int, GlobalState, GlobalAction, ItemState, ItemAction>
Creates a ForEachStore that identifies items by their index.
indexedId<ID, GlobalState, GlobalAction, ItemState, ItemAction>({required Widget builder(BuildContext context, Store<ItemState, ItemAction> store, ID id, int index, int itemCount), required Store<GlobalState, GlobalAction> store, required Iterable<ItemState> getIterable(GlobalState state), required GlobalAction embedAction(ID id, ItemAction localAction), required ID toID(ItemState state), required Widget iterableBuilder({required Widget? itemBuilder(BuildContext, int), int? itemCount}), Widget onEmptyBuilder(BuildContext)?}) → ForEachStore<ID, GlobalState, GlobalAction, ItemState, ItemAction>
Creates a ForEachStore that provides both a custom ID and the index to the builder.