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.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:stream_state/stream_state.dart';
import 'package:stream_state/stream_state_builder.dart';

class AppManager {
  static final AppManager _singleton = AppManager._internal();
  factory AppManager() => _singleton;
  AppManager._internal();

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: StreamStateExample(),
    );
  }
}

class StreamStateExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('StreamState Example Counter!'),
        actions: [
          Row(
            children: [
              Text(
                'Use Red Text',
              ),
              StreamStateBuilder(
                streamState: AppManager().useRedText,
                builder: (context, state) => Checkbox(
                  value: AppManager().useRedText.state,
                  onChanged: (value) => AppManager().useRedText.state = value,
                ),
              ),
            ],
          )
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            StreamStateBuilder<bool>(
              streamState: AppManager().useRedText,
              builder: (context, colorTextState) => StreamStateBuilder<int>(
                streamState: AppManager().counter,
                builder: (context, counterState) => Text(
                  counterState.toString(),
                  style: Theme.of(context)
                      .textTheme
                      .headline4
                      .copyWith(color: colorTextState ? Colors.red : null),
                ),
              ),
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => AppManager().counter.state++,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
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