I have been using Notifier
with void
type for the state. I am wondering is this the recommended way to use notifier or should I just use the normal Provider
? I used this just to access some function.
I have been using Notifier
with void
type for the state. I am wondering is this the recommended way to use notifier or should I just use the normal Provider
? I used this just to access some function.
2
Answers
It makes no sense to use a
Notifier
with typevoid
. It is assumed that:Provider
for a simple state that we cannot change externallyStateProvider
is also for a simple state, but which we can change externally(Async)NotifierProvider
for complex state when you need to have methods to manage itBut one way or another, some state must be stored in each of the providers. That’s the point of it) If there is no state – maybe it’s just a utility class or a repository
Verdict: it makes no sense to use providers with void type state.
Whether it is a
Provider
or aNotifier
, neither should returnvoid
.Returning
void
is generally a sign that something is going wrong. There are some use-cases (such as when returning aStream<void>
for periodic refresh of another provider). But generally, you do not want to do so.From my experience, most people trying to return
void
in a provider only do so because they have split their app into too many small chunks.A
Notifier
is meant to be a full CRUD.You’d meant to do:
Returning
void
inbuild
means that chances are yourhttp.get
is placed in a different provider.