flocse 2.2.0 copy "flocse: ^2.2.0" to clipboard
flocse: ^2.2.0 copied to clipboard

An attempt at component/event based programming with flutter

A new approach to business logic by having all logic be independent components. Unlike Bloc, state is not managed by sending states but by viewmodels, which are components as well.

Features #

  • Seperate your logic from your widgets.
  • Testable and easy to integrate.
  • Easy to learn

Getting started #

At the top level of your app, provide a ComponentRegistry, then anywhere in your app use a ComponentBuilder with your own ComponentViewModel. Register your eventhandlers and add components in the componentregistry.

W.I.P. A proper example will follow. This is a short description...

Usage #

TODO: Include short and useful examples for package users. Add longer examples to /example folder.

class CounterComponent extends Component {
  late int counter;

  @override
  void initListeners() {
    // called before onLoad, use this to register the events
    registerEvent(onIncrement);
    registerEvent(onDecrement);
  }

  Future<void> onIncrement(IncrementEvent e) async {
    // can be fully asynchronous
    await Future.delayed(Duration(milliseconds: Random().nextInt(2000)));
    counter = counter + e.value;
    send(CounterUpdateEvent(counter));
  }

  void onDecrement(DecrementEvent e) {
    // or sync, but will only be called if this exact event is sent
    counter = counter - e.value;
    send(CounterUpdateEvent(counter));
  }

  @override
  void onLoad() {
    // called after register listeners, use this set up your component
    counter = 0;
  }

  @override
  void onUnload() {
      // called right after the listeners are unregistered
  }
}

Additional information #

More information soon to come

4
likes
130
pub points
0%
popularity

Publisher

unverified uploader

An attempt at component/event based programming with flutter

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on flocse