GitHub
Pub.dev
πΒ Veto
A lightweight MVVM state management solution originally inspired by the FilledStacks stacked package.
The example project demonstrates every functionality of this package.
π Β How to use it?
- Create a view model.
import 'package:flutter/material.dart';
import 'package:veto/base_view_model.dart';
class VetoViewModel extends BaseViewModel<String> {
int counter = 0;
@override
Future<void> initialise() async {
debugPrint('''[π] [DEBUG] [π] [VetoViewModel.initialise] [π] I was initialised!''');
super.initialise();
}
@override
Future<void> dispose() async {
debugPrint('''[π] [DEBUG] [π] [VetoViewModel.dispose] [π] I was disposed!''');
super.dispose();
}
void increment() {
counter++;
rebuild();
}
}
- Create a view with the view model.
import 'package:flutter/material.dart';
import 'package:veto/base_view_model.dart';
import 'veto_view_model.dart';
class VetoView extends StatelessWidget {
const VetoView({Key? key}) : super(key: key);
static const String route = 'veto-view';
@override
Widget build(BuildContext context) {
return ViewModelBuilder<VetoViewModel>(
argumentBuilder: () => 'Test',
builder: (context, model) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(model.counter.toString()),
ElevatedButton(
onPressed: model.increment,
child: const Text('Increment'),
),
],
),
),
);
},
viewModelBuilder: () => VetoViewModel(),
);
}
}
- Enjoy MVVM! π
The entire package has extensive documentation. Reading the BaseViewModel
class from top to bottom will give you a good idea of the benefits of this package. Also, a good example project, proper unit tests and some widget tests have been to illustrate and test the most important features of this package. If you have any questions feel free to contact me through codaveto.com.