Created
July 7, 2019 16:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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