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

Lifecycle-aware state management for Dart. ViewModels, async state, stream bindings, and task cancellation.

Piper State #

State management that gets out of your way.

Lifecycle-aware ViewModels, explicit dependencies, automatic cleanup. Patterns that have worked for years, now in Flutter.

Features #

  • StateHolder — Reactive state containers with automatic widget rebuilds
  • AsyncState — Built-in loading/error/data states for async operations
  • Stream bindings — Bind streams to state with automatic subscription management
  • ViewModel — Lifecycle-aware base class with automatic resource cleanup
  • Plain Dart — Core library has no Flutter dependency, test without widgets

Getting started #

dependencies:
  piper_state: ^0.0.2
  flutter_piper: ^0.0.2  # For Flutter widgets

Usage #

Basic state #

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

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

Stream binding #

State updates automatically, subscription auto-cancels on dispose:

class AuthViewModel extends ViewModel {
  AuthViewModel(AuthRepository auth);

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

  bool get isLoggedIn => user.value != null;
}

Async operations #

Loading/error/data handled automatically:

late final profile = asyncState<Profile>();

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

Why Piper? #

  • Explicit dependencies — Constructor injection, not magic
  • Automatic lifecycle — No if (mounted) checks
  • Plain Dart — Test without Flutter
  • Incremental — Adopt one feature at a time

Additional information #

License #

MIT

0
likes
140
points
106
downloads

Publisher

unverified uploader

Weekly Downloads

Lifecycle-aware state management for Dart. ViewModels, async state, stream bindings, and task cancellation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on piper_state