when<T> method
Adds a type mapping using a fluent API.
Returns a new SwitchStore with the T -> builder mapping added.
The builder receives a Store<T, A> scoped to the matched state type.
Implementation
SwitchStore<S, A> when<T>(
Widget Function(BuildContext context, Store<T, A> store) builder,
) {
return SwitchStore(
store: store,
typeMap: Map.fromEntries([
MapEntry(
T,
(context, Store<S, A> store) => builder(
context,
store.scopeState(toLocalState: (p0) => p0 as T),
),
),
...typeMap.entries,
]),
orElse: orElse,
);
}