WithStore<S, A> class

The primary widget for connecting a Store to the Flutter widget tree.

Rebuilds its builder whenever the store's state changes (according to isEqual). The builder receives the current state, a send function for dispatching actions, and the build context.

Basic Usage

WithStore<int, CounterAction>(
  store: store,
  builder: (state, send, context) => Column(
    children: [
      Text('$state'),
      ElevatedButton(
        onPressed: () => send(CounterAction.increment),
        child: Text('Increment'),
      ),
    ],
  ),
);

Scoped Rebuilds

Use WithStore.observe to project state and only rebuild when the projected value changes:

WithStore.observe(
  store: appStore,
  observe: (state) => state.counter,
  builder: (count, send, context) => Text('$count'),
);

See also:

Inheritance
Implementers

Constructors

WithStore({Key? key, required Store<S, A> store, required Widget builder(S state, void send(A), BuildContext context), bool isEqual(S previous, S current) = IsEqualUtils.stateAreEquals})
Creates a WithStore that rebuilds on state changes.
const

Properties

builder → Widget Function(S state, void send(A), BuildContext context)
Builder function called on every state change.
final
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 ==.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
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.
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
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

observe<S, ObservedState, A>({required Store<S, A> store, required ObservedState observe(S state), required Widget builder(ObservedState state, void send(A action), BuildContext context), bool isEqual(ObservedState previous, ObservedState current) = IsEqualUtils.stateAreEquals, Key? key}) → WithStore<ObservedState, A>
Creates a WithStore that projects state via observe before building.
textEditingController<S, A>({required Store<S, A> store, required String toText(S state), required A fromTextEditingAction(TextEditingAction action), required TextEditingControllerWithStoreBuilder<void, A> builder, Key? key}) → WithStore<void, A>
Creates a WithStore with a two-way bound TextEditingController.
textEditingControllerObserve<ObservedState, S, A>({required Store<S, A> store, required ObservedState observe(S observedState), required String toText(S state), required A fromTextEditingAction(TextEditingAction action), required TextEditingControllerWithStoreBuilder<ObservedState, A> builder, bool isEqual(ObservedState previous, ObservedState current) = IsEqualUtils.stateAreEquals, Key? key}) → WithStore<ObservedState, A>
Combines state observation with a TextEditingController binding.
voidBuilder<S, A>(S state, void send(A), BuildContext context) → Widget
A no-op builder used internally by subclasses.