When I try to launch my flutter app on an iOS emulator I get a white blank screen and this:
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
└─Compiling, linking and signing... 13.7s
Xcode build done. 38.0s
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: Invalid argument(s): Object/factory with type Api is already registered inside GetIt.
#0 throwIf (package:get_it/get_it_impl.dart:7:18)
#1 _GetItImplementation._register (package:get_it/get_it_impl.dart:729:5)
#2 _GetItImplementation.registerLazySingleton (package:get_it/get_it_impl.dart:502:5)
#3 setupLocator (package:r/locator.dart:14:18)
#4 main (package:r/main.dart:12:3)
#5 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:140:25)
#6 _rootRun (dart:async/zone.dart:1354:13)
#7 _CustomZone.run (dart:async/zone.dart:1258:19)
#8 _runZoned (dart:async/zone.dart:1788:10)
#9 runZonedGuarded (dart:async/zone.dart:1776:12)
#10 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:133:5)
#11 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
#12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.<…>
Syncing files to device iPhone 12 Pro Max... 137ms
2
Answers
It’s late for your question but I try to explain the problem to those who still face such an error, I hope it helps.
What basically is happening is that a dependency, registered in GetIt instance is being re-registered at some point.
There are three possible solutions
Inspired by This.
This happened to me when I was re-registering my services accidentally in
setUp
in a test. Fixed by usingsetUpAll