-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question: I need to access the latest state of bloc outside of a widget tree in a helper function. #4169
Comments
Hi @ignicubeLaeeq 👋 Can you please provide some additional context regarding what you're trying to achieve? It'd be amazing if you could provide a link to an open source repository that I can checkout and run locally which illustrates the problem you're facing, thanks! |
Hi @felangel ,
I want to do it once on app level and not pass context or token for every api call. |
I highly recommend moving auth token management down into your networking layer. Blocs should generally not know about auth tokens. I recommend using https://pub.dev/packages/fresh_dio. Check out this example for reference https://github.com/felangel/fresh/blob/ce9d5dc202315ef96b6eb04e14d03a667f9bc8f4/packages/fresh_dio/example/packages/jsonplaceholder_client/lib/src/jsonplaceholder_client.dart#L40 |
Thank you for your response.
Theoretically speaking, is there was a way to access my state without context as per my use case? |
Description
I need to access the latest state of bloc outside of widget tree in a helper function.
Desired Solution
Being able to access the bloc without build context or outside of widget tree.
Alternatives Considered
The only alternative i have right now is to pass the context to helper function and access the bloc state.
The text was updated successfully, but these errors were encountered: