Last active
May 7, 2020 23:34
-
-
Save Cretezy/4cc8d9ef15910cc868cba2997586fb59 to your computer and use it in GitHub Desktop.
This file contains hidden or 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:flutter_super_state/flutter_super_state.dart'; | |
// Modules extend `StoreModule` | |
class CounterModule extends StoreModule { | |
// Read only property, to avoid accidentally setting `counter` without calling `setState` | |
int get counter => _counter; | |
var _counter = 0; | |
// This automatically registers your module to your store | |
CounterModule(Store store): super(store); | |
// Synchronous actions | |
void increment() { | |
setState(() { | |
_counter++; | |
}); | |
} | |
void decrement() { | |
setState(() { | |
_counter--; | |
}); | |
} | |
// Asynchronous action | |
Future<void> reset() async { | |
// Fake async delay | |
await Future.delayed(Duration(milliseconds: 10)); | |
setState(() { | |
_counter = 0; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment