Skip to content

Impossible to register inside GetIt #84

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
vince83110 opened this issue May 27, 2020 · 3 comments
Closed

Impossible to register inside GetIt #84

vince83110 opened this issue May 27, 2020 · 3 comments

Comments

@vince83110
Copy link

I am using last version of the plugin, and here is my main.dart file :

final di = GetIt.instance;

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  _registerAppLevelObjects();
  _resetInProgressFlag();

  await DotEnv().load('.env');

  runApp(MyApp());
}

Future<void> _registerAppLevelObjects() async {
  di.registerSingleton(AppDatabase.getInstance());
  di.registerSingleton(DeviceInfoPlugin());
  di.registerSingleton(DeviceInfoRepository(di.get()));
  di.registerSingleton(Api(di.get()));
  di.registerSingleton(DossierRepository(di.get(), di.get()));
  di.registerSingleton(CenterRepository(di.get()));
  di.registerSingleton(SharedPreferences.getInstance());
}

Future<void> _resetInProgressFlag() async {
  final repo = di.get<DossierRepository>();
  repo.resetInProgressFlag();
}

And I have the error :

E/flutter ( 3834): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: 'package:get_it/get_it_impl.dart': Failed assertion: line 251 pos 14: 'instanceFactory != null': No type Api is registered inside GetIt.
E/flutter ( 3834): Did you forget to pass an instance name?
E/flutter ( 3834): (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;did you forget to register it?)

Only DossierRepository relies on Api, so I guess the order is good. How can I debug it ?

@escamoteur
Copy link
Collaborator

I think you really should use types im as generic parameters. Im not sure that the compiler will guess all types correctly

@escamoteur
Copy link
Collaborator

Also, are you sure that your _registerAppLevelObjects has completed when you call _resetInProgressFlag?
Check out the startup synchronization functions of GetIt https://www.burkharts.net/apps/blog/lets-get-this-party-started-startup-orchestration-with-getit/

@escamoteur
Copy link
Collaborator

closing this because of no response

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

2 participants