Core concepts


The following is an exploration of what a Store is conceptually and how they are used in Flutter Forge.


A Store can be thought of as a State Store. It is responsible for facilitating observing and managing state change.

In Practice

The Store is pretty simple and is only interacted with in a few ways.

Constructing a Store

Constructing a Store instance is pretty easy. We simply have to pass it the initialState State, the reducer Reducer, and the environment Environment.

	initialState: const CounterWidgetState(count: 0),
	reducer: counterReducer.debug(name: "counter"),
	environment: CounterWidgetEnvironment()));

Passing a Store to a Widget

The other place you will interact with a Store is when you pass it to a Widget. This is needed so that the Widget knows what its associated State is, such that it can be properly managed.

CounterWidget(store: counterStore);

Sending an Action to a Store

To send an action to the Store from inside a Widget we simply call the send() method on the viewStore that is exposed within the Widget build method. The following is an example of this.

	onPressed: () => viewStore.send(CounterWidgetIncrementButtonTapped()),
	child: const Text("increment"))

Scoping a Store

Another way you will interact with a Store is when you are composing Components together into larger more complex components. In this world you will call one of a handfull of methods on the Store that facilitate you scoping a parents Store down to a Store that is fitting for a child component.

More details can be found in Composing Components.