Does holding a WidgetRef in a service class ensure that reading the provider state always gives the fresh data and not stale data ? #3508
Unanswered
nateshmbhat
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
when i create a service class and pass the Widget ref as a param in its constructor so that i can read any provider state inside the service methods, is it guaranteed that it will give me the latest state value regardless of which ref object I passed from whichever widget ?
I have certain services which need to run independenly from the normal widget cycle and need access to fresh data for example Deeplink handler service , DioUtil that has a dio client with interceptors that inject certain tokens in the request.
So if i initialize these service classes initially by passing the top level MaterialApp (MyApp Widget)
WidgetRef
and holding this ref inside the service classes, at a later point of time, when methods inside these services need the data from the providers, will I get the latest data and is this a good programming approach or is there a better way ?Example code :
Beta Was this translation helpful? Give feedback.
All reactions