mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.4k stars 310 forks source link

Can't make a flutter State a Store #843

Open SrTobi opened 2 years ago

SrTobi commented 2 years ago

Hi

I have a problem after updating to the newest mobx version.

Take the following example:

class _MyWidgetState = _MyWidgetStateBase with _$_MyWidgetState;

abstract class _MyWidgetStateBase extends State<MyWidget> with Store {
  // ...
}

The compiler throws an error:

Superinterfaces don't have a valid override for 'context': State.context (BuildContext Function()), Store.context (ReactiveContext Function()).

Both, flutter's State and mobx's Store have a context method, but with different return types... So I cannot mixin Store into a state.

Is this intentional or unintentional? I guess I'm not supposed to make a State a store, though it worked quite well in the previous version of mobx... Can I work around this anyhow?

fzyzcjy commented 2 years ago

That seems unintentional. But it does not seem to be a good practice to let a state be a store...

amondnet commented 2 years ago

@SrTobi it's a side effect. I never thought of such a case.

SrTobi commented 2 years ago

I guess a solution would be to add a StoreWithoutContext