store_builder 0.2.0 copy "store_builder: ^0.2.0" to clipboard
store_builder: ^0.2.0 copied to clipboard

outdated

Flux store and builder for Flutter

store_builder #

Flux store and builder for Flutter.

Version: 0.2.0

Usage #

Add StoreProvider to your app. Store represents the state of the entire app.

void main() => runApp(MaterialApp(
      title: 'Your app',
      home: StoreProvider(
        store: Store(),
        child: MyHomePage(),
      ),
    ));

Use StoreBuilder<V> to build widgets with the value. Bind to individual values in the Store by name.

child: StoreBuilder<int>(
  name: "counter",
  builder: (BuildContext context, Value<int> value) {
    if (value.error != null) {
        return ErrorWidget(value.error);
    } else if (value.value == null) {
        return LoadingWidget();
    }
    return YourWidget(value.value);
  },
),

You can gets the value from Store by Store#get, or update it by Store#set.

When a value is updates by Store#set, all StoreBuilders associated with that name are rebuilt.

For separation of responsibility, we recommend that you implement store operations independently as Actions.

class IncrementCounterAction implements Action {
  Future<void> run(Store store) async {
    final int counter = store.get<int>("counter").value ?? 0;
    store.set<int>("counter", counter + 1);
  }
}

And widgets calls the action.

class YourWidget extends StatelessWidget {
  
  ...
  
  void incrementCounter() {
    Store.of(context).action(IncrementCounterAction());
  }
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Flux store and builder for Flutter

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on store_builder