How to register ObjectBox in GetIt?

235 Views Asked by At

How to properly register ObjectBox in GetIt? I have an error: The argument type 'Type' can't be assigned to the parameter type 'ObjectBox Function()'.

final injector = GetIt.instance;

class DependencyInitializer {
  DependencyInitializer._();
  static void initDependencies() {
    injector
      //DataBase
      ..registerLazySingleton<ObjectBox>(ObjectBox);
  }
}
1

There are 1 best solutions below

0
On

You have to pass a function/constructor that returns an instance. Passing 'ObjectBox' itself is just the type.

Try this:

  locator.registerLazySingletonAsync<ObjectBox>(() => ObjectBox.create());