flock 0.7.1
flock: ^0.7.1

Flutter Android iOS web

Coordinate Flutter widgets' states with event sourcing. What if Redux store contains no reducers, no state but only actions?

flock #

Build Status

Coordinate Flutter widgets' states with event sourcing.

Inspired by Redux.

Design #

Usage #

import 'package:flock/flock.dart';

// Events
class E {}

class Minus extends E {
  Minus(this.value);

  final String value;
}

class Add extends E {
  Add(this.v);

  final int v;
}

// Store
final store = createStore();

// In you widget:
class BW extends StatelessWidget {
  int sum(int prev, Iterable<E> events, Projectable store) {
    var result = prev ?? 0;
    for (var event in events) {
      if (event is Add)
        result += event.v;
      else if (event is Minus)
        result -= int.tryParse(event.value) ?? 0;
    }
    return result;
  }

  @override
  Widget build(BuildContext context) {
    return StoreBuilder( 
      builder: (BuildContext context, int p) => Text(
            '$p',
            textDirection: TextDirection.ltr,
          ),
      store: store, // use store from wherever you like
      projector: sum
    );
  }
}


Limits #

This is still an early WIP. The future plan includes:

  • better Flutter integration
  • serialization & time travel support

License #

MIT

0
likes
80
pub points
0%
popularity

Coordinate Flutter widgets' states with event sourcing. What if Redux store contains no reducers, no state but only actions?

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

bob432091@gmail.com

License

MIT (LICENSE)

Dependencies

collection, flutter, uuid

More

Packages that depend on flock