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

discontinued
outdated

State management library

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:osam/osam.dart';

void main() => runApp(MyApp());

// ignore: must_be_immutable
class Counter extends BaseState {
  var count = 0;

  @override
  Map<String, Object> get namedProps => {'count': count};
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: StoreProvider(
        child: MyHomePage(),
        store: Store(states: [
          Counter(),
        ]),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final state = StoreProvider.of(context).getState<Counter>();
    return Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'You have pushed the button this many times:',
              ),
              StreamBuilder(
                initialData: state.count,
                stream: state.propertyStream<int>('count'),
                builder: (ctx, AsyncSnapshot<int> snapshot) {
                  return Text(
                    snapshot.data.toString(),
                    style: TextStyle(fontSize: 50),
                  );
                },
              )
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            StoreProvider.of(context).dispatchEvent<Counter>(
                event: Event(reducerCaller: (state, bundle) => state.count++));
          },
          tooltip: 'Increment',
          child: Icon(Icons.add),
        ));
  }
}
9
likes
0
points
15
downloads

Publisher

verified publisherrenesanse.net

Weekly Downloads

State management library

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

equatable, flutter, provider

More

Packages that depend on osam