Most guides instruct to use Provider with Mobx and make the claim that using a singleton is a bad thing while providing no proof or reasoning behind why. Redux uses a singleton for the store and I've never heard an allegation that it's a bad thing. We're talking about global state after all, not local state. It's a singleton by its very nature, that's what you use it as.
My problem with using Provider is that I don't see why even to use something like Mobx when I'm forced to use Provider. Provider already does what it does, and I can use it with context to define my global state. Why even use Mobx at that point? I think the docs could explain this a lot better because I'm not understanding the advantage of Mobx at this point.
Have you ever tried to use flutter_modular with MobX? it gives you a disposable singletons, navigation without context and a modules structure. You also can use it with Slidy CLI that generates all this things for you, eliminates the boilerplate.
Agree, the docs need some more details on why Provider is a good companion library. The primary reason is for flexibility in replacing the instance of Provider with a more specialized one for testing and not having any singletons in the App.
It's a way of being explicit with the dependencies of the UI tree. Singletons will force you to be implicit about dependencies. It's not bad per se, but as you scale your app, you will feel the weight of the implicit set of dependencies making unit testing a bit challenging. MobX does not try to be prescriptive about these dependencies but Provider just happens to be one good way of managing it.
Most helpful comment
Agree, the docs need some more details on why
Provideris a good companion library. The primary reason is for flexibility in replacing the instance ofProviderwith a more specialized one for testing and not having any singletons in the App.It's a way of being explicit with the dependencies of the UI tree. Singletons will force you to be implicit about dependencies. It's not bad per se, but as you scale your app, you will feel the weight of the implicit set of dependencies making unit testing a bit challenging. MobX does not try to be prescriptive about these dependencies but Provider just happens to be one good way of managing it.