Flutter Piper
Flutter widgets for Piper State.
Installation
dependencies:
piper_state: ^0.0.2
flutter_piper: ^0.0.2
Quick Example
// Provide ViewModels
ViewModelScope(
create: [() => CounterViewModel()],
child: MyApp(),
)
// Access and build UI
final vm = context.vm<CounterViewModel>();
vm.count.build((count) => Text('$count'));
Widgets
ViewModelScope
Provides ViewModels to the widget tree:
ViewModelScope(
create: [
() => AuthViewModel(authRepo),
() => TodosViewModel(todoRepo),
],
child: MyApp(),
)
Scoped<T>
Single typed ViewModel with builder:
Scoped<DetailViewModel>(
create: () => DetailViewModel(id),
builder: (context, vm) => DetailPage(),
)
Named Scopes
Share ViewModels across routes:
ViewModelScope.named(
name: 'checkout',
create: [() => CheckoutViewModel()],
child: CheckoutFlow(),
)
// Access by name
context.vm<CheckoutViewModel>(scope: 'checkout');
Building UI
// Rebuild on change
vm.count.build((count) => Text('$count'))
// Side effects
vm.isDeleted.listen(
onChange: (prev, curr) {
if (curr) Navigator.of(context).pop();
},
child: MyWidget(),
)
Documentation
📖 Full docs · GitHub · piper_state
License
MIT
Libraries
- flutter_piper
- Flutter bindings for Piper state management library.