You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to run this codeblock to register a singleton in getit. The console prints "Trying to register navigator" which indicates that the instance is not registered. However when getit the tries to register the singleton it throws.
final navigator =LandingPageNavigator(guards: model.routerGuards);
if (!GetIt.I.isRegistered(instance:LandingPageNavigator)) {
print("Trying to register navigator");
GetIt.I.registerSingleton<LandingPageNavigator>(navigator);
}
Stacktrace:
I/flutter ( 3418): Trying to register navigator
════════ Exception caught by widgets library ═══════════════════════════════════
The following ArgumentError was thrown building BaseWidget<LandingModel>(dirty, state: _BaseWidgetState<LandingModel>#ad5e0):Invalid argument(s): Object/factory with type LandingPageNavigator is already registered inside GetIt.The relevant error-causing widget wasBaseWidget<LandingModel>package:wine_cellar/…/landing-page/landing-page.dart:12When the exception was thrown, this was the stack#0 throwIfpackage:get_it/get_it_impl.dart:7#1 _GetItImplementation._registerpackage:get_it/get_it_impl.dart:675#2 _GetItImplementation.registerLazySingletonpackage:get_it/get_it_impl.dart:455#3 LandingPage.build.<anonymous closure>package:wine_cellar/…/landing-page/landing-page.dart:18#4 _BaseWidgetState.buildpackage:wine_cellar/pages/base-widget.dart:43...════════════════════════════════════════════════════════════════════════════════
The text was updated successfully, but these errors were encountered:
redsuperbat
changed the title
Invalid argument(s): Object/factory with type LandingPageNavigator is already registered inside GetIt.
Invalid argument(s): Object/factory with type XXX is already registered inside GetIt.
Jan 16, 2021
This throws on the first time this part of code is executed? That should be impossible.
But your check if your singleton is registered is wrong. you are passing a type as instance. The instance parameter is only if you want to check if an existing Object is already registered.
You probably want this here:
final navigator =LandingPageNavigator(guards: model.routerGuards);
if (!GetIt.I.isRegistered<LandingPageNavigator>()) {
print("Trying to register navigator");
GetIt.I.registerSingleton<LandingPageNavigator>(navigator);
}
Uh oh!
There was an error while loading. Please reload this page.
Trying to run this codeblock to register a singleton in getit. The console prints "Trying to register navigator" which indicates that the instance is not registered. However when getit the tries to register the singleton it throws.
Stacktrace:
The text was updated successfully, but these errors were encountered: