vm

Creator: coderz1093

Last updated:

0 purchases

vm Image
vm Images

Languages

Categories

Add to Cart

Description:

vm

Flutter VM (ViewModel) #
A very simple flutter plugin that implements the MVVM pattern.
Model–View–ViewModel (MVVM) is a software architectural pattern that facilitates the separation
of the development of the graphical user interface (the view) – be it via a markup language or
GUI code – from the development of the business logic or back-end logic (the model)
so that the view is not dependent on any specific model platform.





Getting Started #

Add this to your pubspec.yaml
dependencies:
vm: ^1.0.3
copied to clipboard

Get the package from Pub:
flutter packages get
copied to clipboard

Import it in your file
import 'package:vm/vm.dart';
copied to clipboard


Features #
...
Usage #
First create a ViewModel
class CounterViewModel extends ViewModel {
int value = 0;
int progress = 0;

void increment() {
value++;
if (value % 5 == 0) {
progress += 1;
}
notifyListeners();
}
}
copied to clipboard
Using CounterViewModel with ViewModelBuilder
ViewModelBuilder<CounterViewModel>(
model: CounterViewModel(),
builder: (context, model, child) {
return Text('Counter: ${model.value}');
},
)
copied to clipboard
Rebuild only if progress changed
ViewModelBuilder<CounterViewModel>(
model: counterModel,
shouldRebuild: (prev, next) => prev.progress != next.progress
builder: (context, model, child) => Text('Progress: ${model.progress}'),
)
copied to clipboard
Or using context.select
ViewModelBuilder<CounterViewModel>(
model: counterModel,
builder: (context, model, child) => const _Progress(),
)
copied to clipboard
class _Progress extends StatelessWidget {
const _Progress({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final progress = context.select((CounterViewModel m) => m.progress);
return Text('Progress: $progress');
}
}
copied to clipboard
Rebuild only if progress is an odd number
ViewModelBuilder<CounterViewModel>(
model: counterModel,
shouldRebuild: (prev, next) => next.progress & 1 == 1,
builder: (context, model, child) => Text('Progress: ${model.progress}'),
)
copied to clipboard
Check out the complete Example
Changelog #
Please have a look in CHANGELOG
Maintainers #

Vlad Korniienko
Alex Awaik

License #

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.