IfLetStore<S, A> class
A widget that conditionally renders content based on nullable state.
When the store's state is non-null, builder is called with a
non-nullable Store<S, A>. When the state is null, orElse is
rendered (or SizedBox.shrink if not provided).
Only rebuilds when the null/non-null status changes, not on every state change within the non-null branch.
Example
IfLetStore<UserProfile, ProfileAction>(
store: profileStore, // Store<UserProfile?, ProfileAction>
builder: (context, store) => WithStore(
store: store,
builder: (profile, send, ctx) => Text(profile.name),
),
orElse: (context) => Text('No profile'),
);
With State Projection
IfLetStore.observe(
store: appStore,
toNullableState: (state) => state.selectedUser,
toGlobalAction: (action) => AppAction.user(action),
builder: (context, store) => UserDetailView(store: store),
);
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- WithStore<
S?, A> - IfLetStore
Constructors
-
IfLetStore({Key? key, required Store<
S?, A> store, required Widget builder(BuildContext context, Store<S, A> store), Widget orElse(BuildContext context)?}) -
Creates an IfLetStore with a nullable state store.
const
Properties
- builder → Widget Function(S? state, void send(A), BuildContext context)
-
Builder function called on every state change.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEqual → bool Function(S? previous, S? current)
-
Equality function to determine whether a state change should trigger
a rebuild. Defaults to
==.finalinherited - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- orElse → Widget Function(BuildContext context)?
-
Widget to render when the state is null.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
store
→ Store<
S?, A> -
The store whose state drives this widget's rebuilds.
finalinherited
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
-
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
-
createBuilder<
S, A> (Widget builder(BuildContext context, Store< S, A> store), Widget orElse(BuildContext context)?, Store<S?, A> store) → dynamic - Creates the internal builder that handles null/non-null branching.
-
observe<
GlobalState, NullableState, GlobalAction, A> ({Key? key, required Store< GlobalState, GlobalAction> store, required Widget builder(BuildContext context, Store<NullableState, A> store), required NullableState? toNullableState(GlobalState state), required GlobalAction toGlobalAction(A action), Widget orElse(BuildContext context)?}) → IfLetStore<NullableState, A> -
Creates an IfLetStore by projecting nullable state from a global store.
override