get_it
The most widely-used service locator/dependency injection library for Flutter and Dart. get_it provides a global service locator pattern: register services (singletons, factories, lazy singletons) and retrieve them anywhere in the app without passing them through widget constructors. Works with any architecture (BLoC, Riverpod, MVVM, clean architecture). Complemented by injectable (code generator) for annotation-driven DI. Key features: singleton registration, factory registration (new instance per get()), lazy singletons (initialize on first access), async initialization, and scope management.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
No network exposure. Global service locator has no security model — access control is application responsibility. Singletons should not store raw credentials; use secure storage and inject only accessors.
⚡ Reliability
Best When
You're building a Flutter app with clean architecture and need global service access across non-widget code (repositories, services, BLoCs) without prop-drilling dependencies through widget constructors.
Avoid When
Your team already uses Riverpod for both state management and DI, or you prefer Provider's widget-tree-scoped approach. get_it and Riverpod solve similar problems with different trade-offs.
Use Cases
- • Register agent service dependencies (API clients, repositories, LLM providers) as global singletons in Flutter apps — access them anywhere without constructor injection chains
- • Use get_it with injectable package for annotation-based DI — @singleton, @lazySingleton, @injectable annotations generate registration code automatically
- • Implement service layers for Flutter agent apps — register ApiService, AgentRepository, AudioService as singletons that are easily mockable in tests
- • Manage async initialization of agent services — registerSingletonAsync for services requiring async setup (database open, credential loading) before app UI shows
- • Create isolated DI scopes per feature using get_it scopes — push/pop scopes for testing or feature-specific service overrides without affecting global registrations
Not For
- • Teams preferring Riverpod for both state management and DI — Riverpod's provider system covers both state and dependency injection without get_it; mixing both adds complexity
- • Apps using Flutter's InheritedWidget or Provider package extensively — Provider package provides widget-tree-scoped DI; get_it is global service locator with different scoping semantics
- • Projects wanting compile-time DI safety — get_it is a runtime service locator; missing registrations throw at runtime not compile time; injectable helps but doesn't eliminate runtime errors
Interface
Authentication
DI framework — no auth concepts. Register auth services (token storage, auth client) as singletons via get_it and access them in interceptors or repositories.
Pricing
get_it is MIT licensed, maintained by Thomas Burkhartdt (fluttercommunity). Free for all use.
Agent Metadata
Known Gotchas
- ⚠ Registration must happen before first access — calling GetIt.I<Service>() before registerSingleton<Service>() throws StateError; ensure setup() runs in main() before runApp()
- ⚠ Test isolation requires resetting get_it — call GetIt.I.reset() in setUp/tearDown to prevent singleton state from leaking between tests; or use allowReassignment to register mock implementations
- ⚠ Async singletons need allReady() — when using registerSingletonAsync, app must await GetIt.I.allReady() before accessing async-initialized services; skip this and get null/uninitialized state
- ⚠ inject package vs injectable — injectable is the code generator companion; get_it itself requires manual registration calls; forgetting to run build_runner after adding @injectable annotations means registrations don't exist
- ⚠ Global state makes testing harder without discipline — get_it's global nature means tests must carefully set up and tear down registrations; use getIt.allowReassignment = true for test environments to register mocks
- ⚠ Scoped registrations with pushNewScope/popScope — scopes are stack-based; popping a scope disposes scoped registrations; accidentally popping too early removes services mid-feature; scope lifecycle must match feature lifecycle
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for get_it.
Scores are editorial opinions as of 2026-03-06.