Skip to content

Instantly share code, notes, and snippets.

@Aidanvii7
Created July 7, 2019 16:02
Show Gist options
  • Save Aidanvii7/6c338c4bab9ed7c4f21754aac6d47ad7 to your computer and use it in GitHub Desktop.
Save Aidanvii7/6c338c4bab9ed7c4f21754aac6d47ad7 to your computer and use it in GitHub Desktop.
Example of using MobX Dart with Flutter's Counter example, plus some extras
import 'package:mobx/mobx.dart';
part 'counter_store.g.dart';
class CounterStore = _CounterStore with _$CounterStore;
abstract class _CounterStore with Store {
@observable
int counter1 = 0;
@observable
int counter2 = 0;
@computed
int get counterSum => counter1 + counter2;
@action
void increment1() {
counter1++;
}
@action
void increment2() {
counter2++;
}
@action
void reset() {
counter1 = 0;
counter2 = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment