0

I am very much new to the mobx and want to use it as state management for my application. so far with the online tutorial and google search I know that mobx is the state management tool similar to ChangeNotifier in the flutter and best used with provider to elegantly manage the state of the widget.

So far, it makes sense to manage the state screen wise:- for that I create the store which will only be a concern for this screen only, and after declaring the @observable state variables, I wire them up with business logic and provide it to the concerned screen.

But there are states which have to be managed across the screen, where the state of the current screen is dependent on the state of the previous screen.

So, what is the best way to manage the state across the screen using Mobx? For now, I would create one global Store (the reason it is global because I want to access this store in the individual screen store also for some business logic) which will be available across multiple screens made available using provider. And used in the individual Store to manage the state.

But somehow making state global doesn't seem right? so, what is a possible solution for this? what is the most elegant way to manage state across multiple screens in flutter using mobx?

rahul Kushwaha
  • 2,395
  • 7
  • 32
  • 64

1 Answers1

1

You can use Provider and MobX together, create and provide the same instance of your MobX class to any screen that needs it.

Edit: I guess I didn't read the whole question, what do you mean when you say a Global MobX Store?

And now that I'm thinking about it, you may want to create a GetIt instance of the store and just grab that in any screen you want, but I cannot say that one of them is better than the other and definitely not the best way.

de_tail
  • 11
  • 3