stream_state 0.0.1 copy "stream_state: ^0.0.1" to clipboard
stream_state: ^0.0.1 copied to clipboard

outdated

A very thin wrapper around streams for simple but easy to use state management.

StreamState #

StreamState is an extremely thin wrapper around streams to make them a very simple but easy to use state management option.

How to use #

To add some new bit of state simply create a StreamState with an initial value:

    var counter = StreamState<int>(initial: 0);
    var useRedText = StreamState<bool>(initial: true);

It is very easy to update the state:

    counter++;
    useRedText = !useRedText;

StreamStateBuilders will automatically update your UI when the state changes:

    StreamStateBuilder<bool>(
        streamState: useRedText,
        builder: (context, useRedTextState) => StreamStateBuilder<int>(
            streamState: counter,
            builder: (context, counterState) => Text(
                counterState.toString(),
                style: TextStyle(color: useRedTextState ? Colors.red : null),
        ), //StreamStateBuilder
    ), //StreamStateBuilder

Included Example #

The included counter example uses a singleton to store the state for simplicity. This makes it very easy to access your state from anywhere in your app. You can create as many of these singletons as you'd like to separate the logic of your code.

You could also store your StreamStates in any other way, including just in a stateful widget.

8
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A very thin wrapper around streams for simple but easy to use state management.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on stream_state