zubairehman / flutter_boilerplate_project

A boilerplate project created in flutter using MobX and Provider.
http://zubairehman.surge.sh/
MIT License
2.26k stars 908 forks source link

How to inject a repository to a store(which is not created in main.dart) ? #84

Closed blackkara closed 3 years ago

blackkara commented 3 years ago

You just injected the repository to ThemeStore and LanguageStore in main.dart, thats okay.

So what about the FormStore ? As the title says, how to inject the repository ?

zubairehman commented 3 years ago

Hi @blackkara,

In my case, FormStore doesn't need a repository but still if you have a case where you want to pass the repository then have a look at the code below:

FormStore _formStore = FormStore(getIt<Repository>());

or

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _formStore = = FormStore(getIt<Repository>());
  }

Thanks.