get_it
9.3.0, released 2 months ago by flutter-it.dev
A fast, type-safe service locator for Dart and Flutter without BuildContext or code generation.
What it does
Decouples interfaces from implementations by providing a global container to register and retrieve objects. Supports singletons, lazy singletons, factories, asynchronous initialization, and hierarchical scopes. Includes a Flutter DevTools extension to inspect registrations and their states at runtime.
AI-written summary of version 9.3.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to access dependencies from business logic or background code without a BuildContext
- You prefer runtime manual registration over code generation and annotations
- You need scoped lifetimes, async object orchestration, or easy mock swapping in tests
Skip it when
- You prefer compile-time dependency injection managed via code generation
- You strictly avoid global state and service locator patterns
Strengths
- O(1) lookups using Dart maps with no code-generation overhead or build_runner steps
- Rich lifecycle management including scopes, async initialization readiness (`allReady`), and LIFO disposal
- Includes a dedicated DevTools extension to visually inspect registered objects
Weaknesses
- Relies on runtime resolution, meaning missing registrations fail at runtime rather than compile-time
- Service locator pattern can obscure direct class dependencies if overused
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 3
Pure Dart package with no platform-specific configuration needed. Optional DevTools extension setup requires enabling debug events.
final getIt = GetIt.instance;
void configureDependencies() {
getIt.registerSingleton<ApiClient>(ApiClient());
getIt.registerLazySingleton<UserRepository>(() => UserRepository(getIt<ApiClient>()));
}
// Access anywhere
final repo = getIt<UserRepository>();Alternatives
Packages that do the same job and could replace get_it.
Works with
Packages commonly used together with get_it: ones it builds on, ones built on it, and its own family.
- asyncget_it depends on itUtility classes and helpers that extend Dart's async library.
- injectableBuilt on get_itConvenient code generator for get_it dependency injection.
- msixBuilt on get_itCLI tool that creates MSIX installers from Flutter Windows build outputs.
- stacked_sharedBuilt on get_itShared code between the stacked packages.
- stackedBuilt on get_itA complete frontend architecture framework for building Flutter applications.
- watch_itBuilt on get_itState management powered by get_it to observe changes and rebuild widgets automatically.
- network_toolsBuilt on get_itDiscover open ports, devices on a subnet, and perform network scanning.
- reown_appkitBuilt on get_itFlutter toolkit for WalletConnect onchain UX