Piper State

Piper State

pub package likes popularity pub points CI codecov License: MIT Dart style: lints

Flutter state management that cleans up after itself.

  • ✅ Automatic rebuilds — tracked reads, no dependency lists
  • ✅ Lifecycle-owned cleanup — streams and cooperative tasks stop on dispose
  • ✅ Explicit dependencies — constructor injection keeps the graph visible
  • ✅ Plain Dart — no code generation, direct unit tests

Installation

For Dart-only projects:

dependencies:
  piper_state: ^0.1.0

Flutter apps can install flutter_piper: ^0.1.0 instead; it re-exports this package and adds scopes, builders, and listeners.

Quick Example

class CounterViewModel extends ViewModel {
  late final count = state(0);

  void increment() => count.update((c) => c + 1);
}

// In your widget
vm.count.build((count) => Text('$count'));

Stream Binding

class AuthViewModel extends ViewModel {
  final AuthRepository _auth;

  AuthViewModel(this._auth);

  late final user = bind(_auth.userStream, initial: null);
}

Async Operations

late final profile = asyncState<Profile>();

void loadProfile() => load(profile, () => _repo.fetchProfile());

Why Piper?

Piper Riverpod Bloc
Dependencies constructor ref.watch / ref.read constructor
State changes methods providers + notifiers methods (Cubit) or events (Bloc)
Code generation none optional optional
Testing plain Dart test() ProviderContainer.test() blocTest

Piper favors plain objects over a provider graph or event log. See the full comparison for the trade-offs and async cancellation details.

Documentation

📖 Full docs · GitHub · flutter_piper

License

MIT

Libraries

piper_state
A lightweight state management library for Flutter.