Skip to content

Instantly share code, notes, and snippets.

@isacjunior
Created November 26, 2020 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isacjunior/652ac2044365c34d145c17fda8df7838 to your computer and use it in GitHub Desktop.
Save isacjunior/652ac2044365c34d145c17fda8df7838 to your computer and use it in GitHub Desktop.
class Counter {
Counter({this.count});
int count;
void increment() {
count++;
}
void decrement() {
count--;
}
}
enum CounterTypes {
increment,
decrement,
}
class CounterStore with ChangeNotifier {
Counter _counter = Counter(count: 0);
int get count => _counter.count;
void dispatch(CounterTypes type) {
final action = {
CounterTypes.increment: _counter.increment,
CounterTypes.decrement: _counter.decrement,
}[type];
action();
notifyListeners();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment