Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Counter ViewModel for MVVM architecture
import 'package:flutter/foundation.dart';
class CounterViewModel extends ChangeNotifier { // <-- extends ChangeNotifier
int _counter = 0;
int get counter => _counter;
void increment() {
_counter++;
notifyListeners(); // <-- notify listeners
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment