Closed smiLLe closed 4 years ago
Shouldn't this be the responsibility of the provider instead? Like with updateShouldNotify
Mh yes, but what if i am not using a provider .addListener((state) => persist(state));
My widget tree would not update because of updateShouldNotify
, however, the listener would be called.
Thinking of it. Persisting the state could be a widget as well. updateShouldNotify
will work in that case
Even then, we don't need a new method for that.
We can do:
@protected
@overide
set state(MyState state) {
if (state != this.state) {
super.state = state;
}
}
I didn't check ==
on StateNotifier
because that's already the default behavior of StateNotifierProvider
, and that would lead to comparing the object twice for no reason.
But the tools necessary to do such things are available
Alright, i close this :)
Hi, i just added some code rather than creating an issue. The idea is to have an easy way to deny a state change, for example where state must be distinct. You can always override the state setter, but i thought it might be easier to have a seperate callback function. In addition we can add helper functions like
stateIsDistinct()
to be used inallowTransition
.Note; there is no documentation etc. I will add more if you like the idea :)