velo library
A simple and efficient state management solution for Flutter.
Velo is inspired by flutter_bloc's Cubit pattern but focuses on simplicity
and efficiency. It builds upon Flutter's native ValueNotifier and integrates
with Equatable for optimal state comparisons.
Getting Started
- Define your state class using
Equatable:
class CounterState extends Equatable {
final int count;
const CounterState({this.count = 0});
@override
List<Object?> get props => [count];
}
- Create a Velo class to manage your state:
class CounterVelo extends Velo<CounterState> {
CounterVelo() : super(const CounterState());
void increment() {
emit(state.copyWith(count: state.count + 1));
}
}
- Use Velo widgets in your UI:
VeloBuilder<CounterVelo, CounterState>(
builder: (context, state) {
return Text('Count: ${state.count}');
},
)
Available Widgets
- VeloBuilder: Rebuilds when state changes
- VeloListener: Performs side effects without rebuilding
- VeloConsumer: Combines builder and listener functionality
- MultiVeloListener: Provides multiple Velo instances
Integration with Provider
Velo works seamlessly with the Provider package:
Provider<CounterVelo>(
create: (_) => CounterVelo(),
dispose: (_, velo) => velo.dispose(),
child: MyApp(),
)
Classes
- MultiVeloListener
- A widget that provides multiple Velo instances to the widget tree.
-
Velo<
S> -
A state management class that extends ValueNotifier with
Equatablesupport. -
VeloBuilder<
N extends Velo< T> , T> - A widget that listens to a Velo and rebuilds whenever the state changes.
-
VeloConsumer<
N extends Velo< T> , T> - A widget that combines VeloBuilder and VeloListener functionality.
-
VeloListener<
N extends Velo< T> , T> - A widget that listens to changes in a Velo without rebuilding.