-
-
Notifications
You must be signed in to change notification settings - Fork 153
registerFactory not working with bloc #151
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
Comments
Everything is working except the bloc. Bloc is not changing its state while the app is perfectly making login request to the backend. Only problem is that the bloc state is not changing. If I use registerLazySingleton instead of registerFactory then everything works smooth. Even bloc works fine but I encountered a bug using lazySingleton. |
Unfortunately you haven't added the part of the code where you use the UserLoginBloc. Why can't you use a LazySingleton? |
Thank you @escamoteur but I recently fixed the problem. I'll just mention how I fixed my problem so others with same issue see. I was adding events directly as The problem was the events were passed to the new instance of Bloc as I was using registerFactory() in get_it.
and added events to the bloc as
which worked as expected and updated the UI. It was problem with my code and not get_it. Sorry and thank you! |
Btw you could always use a singleton in combination with GetIt Scopes then you don't run into this problems if you want to have only short lived BLoCs |
Hello @escamoteur . I am using get_it on my app with login system. The problem I am facing is when the user log's out and another user logs in, the previously logged in user data is shown. You mentioned about new feature of scopes in get_it. But unfortunately I can find no example all over the internet [including get_it docs] on how I can use scope feature. Can you please provide an example on how to use this feature. Also update the docs since there's no point in having a feature when you don't let the users know how those features comes handy. |
Did you check the docs of the V5.0.0 of get_it? |
Is there an actual example of how to work with it? |
Don't think so, a look at the tests for it in the get_it package might help. |
This is how I register types when app starts.
I want to unregister the AccountBloc's when user logs out registered in di.init() and re register when another user logs in. account.dart
|
you don't do the login register at the beginning of your app but at the moment you do the loginpage. |
Thank you! Solved my problem. All I didn't know was when to call pushNewScope and popScope. Pushing scope
Popping Scope
It was confusing on how and where to use those push and pop scopes. Apart from that it's really simple. |
I agree, I should add that. |
actually you even could pop the scope from your BLoC at the end of the |
Been trying days to figure out why the registerFactory is not changing the state of the bloc.
main.dart
user_login_injection_container.dart
user_login_injection_container.dart
user_login_event.dart
user_login_state.dart
The text was updated successfully, but these errors were encountered: