-
-
Notifications
You must be signed in to change notification settings - Fork 153
Factory not registered? It is! #137
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
I think I spotted it in your config.dart file gh.factory<SharedPreferences>(() => sharedPreferences); I think that should be gh.factory<SharedPreferences>(() => sharedPreferences()); |
Hey @escamoteur thanks for the reply, but that's not the issue because I think it has to be because of the await & async functionality, something is not working correctly |
Sorry, missed that. Yeah, your problem is your init function is not awaited as it looks like injectable doesn't know how to deal with async singeltons. |
did you solve it? |
Hey sorry, yes I solved it. I had to make the
Then
Yeah, I think the developers from Injectable need to add the possibility to create async factories. Thanks for your help! |
Glad to hear this. |
Oh yeah, I was thinking of doing that. But I don't know how to exactly to do so, because this is how my code looks right now. My MaterialApp widget is like this
I'm using the BLoC library to provide the AuthBloc (which determines if the user is logged in or not) to all the widgets in my app. For that reason, I have a MultiblocProvider as the parent of my MaterialApp As you can see, I'm using getIt to get the AuthBloc from there, so I need to have the getIt injections configured by there. I'm also using a Splash Page to decide whether to show the Login Page or the Home Page. This Splash Page is the initial route of my navigator "/", so it's a child of the MaterialApp
And I feel like this would be the perfect spot to add any awaits (like As you can also see I'm using a If I did all of this my code would like something like this: My MaterialApp widget would like like this. I remove the BlocProvider.
Then I would change my Splash Page to something along these lines:
I'm not sure about the authBloc.state.first part, but I think I could change it to listen to the state changes instead of awaiting. I hope I explained myself. It would be super helpful if you could illuminate me with a solution to put all those asynchronous functions in the SplashPage :) |
I'm getting an error telling me that I don't have a factory registered, but I'm trying to get it
This is the class I'm trying to get but as you can see it's annotated with @Injectable
Also in the injection.config.dart you can clearly see that the AuthBloc has it's factory defined
This is my main.dart
Here is where I'm trying to getIt
This is the injection.dart file
This is the error message I'm getting
These are my pubspeck.yaml dependencies
Please help, I need to turn this code next week! D:
The text was updated successfully, but these errors were encountered: