Comments (5)
I've created a quick sample to illustrate this common request, maybe others will also find it useful.
You can check it out here 🎉
from cubit.
HI @RollyPeres,
yes, you are right, it makes totally sense now. I also found out, that when I would change the skip to 0, then I get another undesigned behavior, in the sign-in/signout flow. So it must be some architecture-related issues.
Thanks for pointing it out. I will look into the example you've posted. Since I am also using the Auto_route package, I will have to look at how I can make it work together.
from cubit.
Hi @Manuelbaun 👋
Thanks for opening an issue!
Cubit is still async and this isn't specific to cubit (you can have a race-condition with listeners with bloc as well). I would highly recommend lifting your listener up in the widget tree to be above where the method is called. That guarantees the listener is mounted before anything has happened.
If you're still having trouble, it would be great if you could share a link to a sample github repo which illustrates the problem you're having. Thanks! 👍
from cubit.
Hi @Manuelbaun 👋
The listener is by design implemented in such a way that it will only react to state changes after it is mounted into the tree, since it doesn't make sense to react to the last known state since that might be obsolete by the time the listener subscribes to the stream of states.
Your issue raises from your architecture. Your CubitListener<AuthCubit, AuthState>
should be placed globally instead of scoping it to your splash screen, because you always want it to be ready to react to state changes in your authentication.
A good place to provide it would be inside MaterialApp
's builder
.
You can check out this example and adapt it to cubit.
Hope it helps 👍
from cubit.
I looked into the example and I could refactor authentication as you suggested and provided it to the builder in the MaterialApp.
However, the example uses bloc with the async event dispatch, but Cubit uses methods (sync).
But the issue remains:
I need to call the method checkIfAuthenticated
of the AuthCubit
after the CubitListener
listens to the AuthCubit
. Then the listener would be triggered properly and I can navigate to another page.
But currently, there is no way, to find out, when the CubitListener is mounted to the tree. So if call the checkIfAuthenticated
method just before its mounted, then I will not be able to navigate to another page.
I could use a time delay, but it a dirty hack and potential for a race condition.
Do you have an idea of how I can manage that?
from cubit.
Related Issues (18)
- Thoughts HOT 3
- Allow cubit to override the provider HOT 2
- Why do we need to specify the cobit state type in the cubitBuilder? HOT 2
- Cubit Delegate/Supervisor missing? HOT 1
- Provide a example in how to emit a complex object state HOT 2
- CubitModule? HOT 3
- Observer in Cubit? HOT 3
- Snippets HOT 1
- [DISCUSSION] Should Cubit expose Stream API? HOT 12
- [HELP] Emit state from a stream in repository HOT 2
- Emitted state not received by CubitBuilder HOT 20
- Scale cubit with bloc capabilities HOT 4
- ReplayCubit - List with mutated state can not be redo / undo HOT 11
- Preserve intialState of a cubit HOT 5
- What scopes API should look like? HOT 5
- [PROPOSAL] Merge Cubit into Bloc HOT 32
- Get state without builder HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cubit.