reflux 0.11.0-beta copy "reflux: ^0.11.0-beta" to clipboard
reflux: ^0.11.0-beta copied to clipboard

Predictable state container for Dart apps - inspired by Redux patterns

Reflux #

Redux-inspired state management for React with Dart (dart_node) and Flutter.

Predictable state container with full type safety using Dart's sealed classes for exhaustive pattern matching.

Getting Started #

import 'package:reflux/reflux.dart';

// State as a record
typedef CounterState = ({int count});

// Actions as sealed classes
sealed class CounterAction extends Action {}
final class Increment extends CounterAction {}
final class Decrement extends CounterAction {}

// Reducer with pattern matching
CounterState counterReducer(CounterState state, Action action) =>
    switch (action) {
      Increment() => (count: state.count + 1),
      Decrement() => (count: state.count - 1),
      _ => state,
    };

void main() {
  final store = createStore(counterReducer, (count: 0));

  store.subscribe(() => print('Count: ${store.getState().count}'));

  store.dispatch(Increment()); // Count: 1
  store.dispatch(Increment()); // Count: 2
  store.dispatch(Decrement()); // Count: 1
}

Part of dart_node #

GitHub

0
likes
145
points
142
downloads

Publisher

verified publisherchristianfindlay.com

Weekly Downloads

Predictable state container for Dart apps - inspired by Redux patterns

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

austerity, dart_logging, nadz

More

Packages that depend on reflux