neat_state 0.0.2 copy "neat_state: ^0.0.2" to clipboard
neat_state: ^0.0.2 copied to clipboard

Nice and simple app global state

Nice and simple app global state based on bloc package

Usage #

Create a global state for your app (add optional onChangeCallback):

final NeatState<AppState> appState = NeatState<AppState>(
  initialState: const AppState(counter: 0),
  onChangeCallback: (Change<AppState> change) {
    print('exampleBasic:onChangeCallback: ${change.currentState} => ${change.nextState}');
  },
);

Get access to value of state:

print('exampleBasic: init, counter=${appState.state.counter}');

Change state with replace method:

appState.replace(appState.state.copyWith(counter: appState.state.counter + 1));

or with update method (sometimes it may be more convenient):

appState.update((AppState state) => state.copyWith(counter: state.counter + 1));

Listen to the state changes:

final StreamSubscription<AppState> subscription1 = appState.stream.listen((AppState state) {
  print('exampleBasic:subscription1: counter=${state.counter}');
});

Listen only to some part of state changes:

final StreamSubscription<int> subscription2 =
      appState.subState<int>((AppState state) => state.counter).listen((int counter) {
    print('exampleBasic:subscription2: counter=$counter');
  });

Additional information #

bloc Single source of truth

1
likes
130
pub points
0%
popularity

Publisher

unverified uploader

Nice and simple app global state

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc

More

Packages that depend on neat_state