Mobx.dart: Can I do autorun in builder?

Created on 6 Sep 2019  路  5Comments  路  Source: mobxjs/mobx.dart

I have provider object (mobx store) in builder function. I want to monitor that. Right now in store constructor I have autorun wired up. Is doing inside widget possible?

Thx

Most helpful comment

Provider(
  builder: (_) => MyStore(),
  dispose: (_, store) => store.dispose(),
)

As for obtaining the store inside initState you can do:

initState() {
  Provider.of<MyStore>(context, listen: false);
}

All 5 comments

If you have a StatefulWidget, you could do in the initState(). Make sure to also dispose in the dispose()

@pavanpodila Thx for getting back, but can I get store from provider in initState?
Only way I guess right now might be with binding after layout render. https://pub.dev/packages/after_layout

Ah yes, I forgot about that. @rrousselGit can we pull a Store from Provider inside initState?

Provider(
  builder: (_) => MyStore(),
  dispose: (_, store) => store.dispose(),
)

As for obtaining the store inside initState you can do:

initState() {
  Provider.of<MyStore>(context, listen: false);
}

Thx a bunch guys!! really helpful.

Was this page helpful?
0 / 5 - 0 ratings