Skip to content

Instantly share code, notes, and snippets.

Last active November 3, 2020 05:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chimon2000/7982cc4fd86e88cd46328590bc5b26b5 to your computer and use it in GitHub Desktop.
state_example: mobx page
class MobxPage extends StatefulWidget {
const MobxPage({Key key}) : super(key: key);
_MobxPageState createState() => _MobxPageState();
class _MobxPageState extends State<MobxPage> {
var _notesStore = Notes();
TextEditingController _controller;
void initState() {
_controller = TextEditingController();
void dispose() {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('My notes app')),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
onPressed: () {
// Execute addNote action
// to add a note.
child: Text('Create Note')),
controller: _controller,
// Execute updateInput action
// to update the input value.
onChanged: _notesStore.updateInput,
decoration: InputDecoration.collapsed(hintText: 'Add a note'),
// Use Observer to subscribe
// to updates to the NotesStore.
builder: (_) => Expanded(
child: ListView.builder(
itemBuilder: (context, index) =>
Note(text: _notesStore.notes[index]),
itemCount: _notesStore.notes.length,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment