Skip to content

got a problem with getIt.isReady? #269

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

Closed
freewebwithme opened this issue Mar 31, 2022 · 2 comments
Closed

got a problem with getIt.isReady? #269

freewebwithme opened this issue Mar 31, 2022 · 2 comments

Comments

@freewebwithme
Copy link

First I try to register PhoenixSocket type and to make sure that GraphQLClient is registered I check

  print(getIt.isRegistered<GraphQLClient>());

  // Register Phoenix Socket
  getIt.isReady<GraphQLClient>().then((value) =>
      getIt.registerSingletonAsync<PhoenixSocket>(
          ()  =>  Client().initializeSocket()));

And here isinitializeSocket()

class Client {
  Box? box;
  String? token;

  Client() {
    box = getIt<Box>();
    token = box!.get("userToken");
  }

  Future<PhoenixSocket> initializeSocket() async {
    print("Initializing Socket...");
    return PhoenixSocket(
      wsEndpoint,
      socketOptions: PhoenixSocketOptions(
        //params: {"token": token},
        dynamicParams: (() => getAToken()),
      ),
    );
  }
}

And register another type that depends on PhoenixSocket type.


  getIt.isReady<PhoenixSocket>().then((value) => getIt
      .registerSingleton<ICartChannel>(CartChannel(getIt<PhoenixSocket>())));

But I got an error

E/flutter (10182): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:get_it/get_it_impl.dart': Failed assertion: line 372 pos 7: 'instanceFactory != null': Object/factory with  type PhoenixSocket is not registered inside GetIt. 
E/flutter (10182): (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
E/flutter (10182): Did you forget to register it?)
E/flutter (10182): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (10182): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter (10182): #2      _GetItImplementation._findFactoryByNameAndType (package:get_it/get_it_impl.dart:372:7)
E/flutter (10182): #3      _GetItImplementation.isReady (package:get_it/get_it_impl.dart:1286:24)
E/flutter (10182): #4      afterAuthenticationGetIt (package:myApp/getit_setup.dart:108:9)
E/flutter (10182): #5      AuthenticationApi.status (package:myApp/api/apis/authentication_api.dart:74:17)
E/flutter (10182): <asynchronous suspension>
E/flutter (10182): #6      new AuthenticationBloc.<anonymous closure> (package:myApp/authentication/bloc/authentication_bloc.dart:21:17)
E/flutter (10182): <asynchronous suspension>

I tried to find a bug but it took me a day and still can't figure out!
Please give me an advice!

@AdamMusa
Copy link

AdamMusa commented Apr 3, 2022

You have to register PhoenixSocket an inside GetIt .
I want to see how you get get_it instance because the stacktrace to clair .

@escamoteur
Copy link
Collaborator

you can use the dependsOn parameter to ensure that your first object is ready before the second is registered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants