Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Covers get_it service locator for Flutter/Dart: registration, scopes, async init, retrieval, and scope-based test mocking.
46% 92%+46 ptsof test cases passed
Passed 22 of 24 test cases with the skill, and 11 of 24 without it.
3 of 3 safety checks passed
Not used yet
What: Type-safe service locator with O(1) lookup. Register services globally, retrieve anywhere without BuildContext. Pure Dart, no code generation.
runApp()pushNewScope() is synchronous. Use pushNewScopeAsync() for async initpopScope() IS async (returns Future<void>)allReady() returns Future<void> - await it or use FutureBuilder/watch_itallReady()), access them with normal getIt<T>() - no getAsync neededdi alias for GetIt.I is already provided - use di<T>() instead of getIt<T>()registerLazySingleton<Iface>(getIt.call) re-enters get<Iface>(). Since 9.3.0 lazy singletons (sync/async) and cached factories throw a descriptive StateError for circular self-resolution instead of a StackOverflowError; plain factories are not guarded (recursive factories are legitimate). Use () => getIt<Impl>()final getIt = GetIt.instance;
void configureDependencies() {
// Singleton - created immediately
getIt.registerSingleton<ApiClient>(ApiClient());
// Singleton with dispose callback
getIt.registerSingleton<StreamController>(
StreamController(),
dispose: (c) => c.close(),
);
// Lazy singleton - created on first access
getIt.registerLazySingleton<Database>(() => Database());
// Factory - new instance every call
getIt.registerFactory<Logger>(() => Logger());
// Factory with parameters
getIt.registerFactoryParam<Logger, String, void>(
(tag, _) => Logger(tag),
);
Next to this one in the catalogue, plus more from the same author.