Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App"
Package selection guidance compiled from public package information, community data, and project usage.
GetIt is a lightweight, simple service locator for Dart and Flutter that enables dependency injection by decoupling interfaces from their concrete implementations. It allows developers to register and retrieve services globally throughout the app with minimal boilerplate. GetIt supports lazy instantiation, factory registration, and easy testing through mocking. It's ideal for managing shared dependencies like repositories, APIs, or state managers across different parts of an application.
Use cases
Managing shared services across multiple widgets
Testing with mocked dependencies
Injecting repositories and API clients
Simplifying state management setup
Decoupling UI from business logic
Key features
Simple API with minimal setup
Supports lazy and eager instantiation
Factory and singleton registration
Easy to mock for unit testing
Lightweight and fast
Suitable for
Small to medium-sized Flutter apps
Developers new to dependency injection
Projects needing quick DI integration
Teams prioritizing simplicity over complexity
Apps requiring testable service layers
Considerations
Not suitable for large-scale enterprise apps with complex DI needs
Manual registration can lead to runtime errors if not managed carefully
Limited built-in lifecycle management compared to advanced DI frameworks
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
A blazing-fast service locator for Dart and Flutter that makes dependency management simple.
As your app grows, you need a way to access services, models, and business logic from anywhere without tightly coupling your code to widget trees. get_it is a simple, type-safe service locator that gives you O(1) access to your objects from anywhere in your app—no BuildContext required, no code generation, no magic.
Think of it as a smart container that holds your app's important objects. Register them once at startup, then access them from anywhere. Simple, fast, and testable.
flutter_it is a construction set — get_it works perfectly standalone or combine it with other packages like watch_it (state management), command_it (commands), or listen_it (reactive operators). Use what you need, when you need it.
Why get_it?
⚡ Blazing Fast — O(1) lookups using Dart's native Maps. No reflection, no slow searches.
🎯 Type Safe — Full compile-time type checking with generics. Errors caught before runtime.
🧪 Test Friendly — Easily swap real implementations for mocks. Reset and reconfigure between tests.
🌳 No BuildContext — Access your objects from anywhere—business logic, utilities, even pure Dart packages.
📦 Framework Agnostic — Works in Flutter, pure Dart, server-side, CLI apps. No Flutter dependencies required.
🔧 Zero Boilerplate — No code generation, no build_runner, no annotations. Just register and use.
import'package:get_it/get_it.dart';
// Create a global instance (or use GetIt.instance)final getIt = GetIt.instance;
// 1. Define your servicesclassApiClient{
Future<void> fetchData() async { /* ... */ }
}
classUserRepository{
finalApiClient apiClient;
UserRepository(this.apiClient);
}
// 2. Register them at app startupvoidconfigureDependencies() {
getIt.registerSingleton<ApiClient>(ApiClient());
getIt.registerLazySingleton<UserRepository>(
() => UserRepository(getIt<ApiClient>())
);
}
// 3. Access from anywhere in your appclassMyHomePageextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
returnElevatedButton(
onPressed: () {
// No BuildContext passing needed!
getIt<UserRepository>().apiClient.fetchData();
},
child: Text('Fetch Data'),
);
}
}
That's it! Three simple steps: define, register, access.
Key Features
Registration Types
Choose the lifetime that fits your needs:
Singleton — Create once, share everywhere. Perfect for services that maintain state.
Read more →
LazySingleton — Create on first access. Delays initialization until needed.
Read more →
Factory — New instance every time. Great for stateless services or objects with short lifetimes.
Read more →
Avoid untyped tear-offs as factories. Registering getIt.call (or an untyped getIt.get tear-off) as registerLazySingleton<Iface>(...) re-enters get<Iface>() and used to overflow the stack. For lazy singletons (sync and async) and cached factories GetIt now detects this circular self-resolution and throws a descriptive StateError. Plain registerFactory factories are not guarded, since a factory that recursively resolves its own type (e.g. to build a tree) is a legitimate pattern. Prefer () => getIt<Impl>() or a named function that keeps the concrete type argument.
Advanced Features
Scopes — Create hierarchical registration scopes for different app states (login/logout, sessions, feature flags).
Read more →
Async Objects — Register objects that need async initialization with dependency ordering.
Read more →
Startup Orchestration — Easily orchestrate initialization of asynchronous objects during startup.
Read more →
Named Instances — Register multiple implementations of the same type with different names.
Read more →
Multiple Registrations — Register multiple implementations and retrieve them all as a collection.
Read more →
Unregistering — Remove registrations with unregister(), optionally disposing the instance. By default unregister() throws if nothing matching is registered (usually a sign that you dispose once too often); set getIt.skipUnregisterIfNotRegistered = true to silently ignore a missing registration instead.
Read more →
Testing Support
get_it makes testing a breeze:
Easy Mocking — Replace real implementations with mocks using allowReassignment or reset()
Test Isolation — reset() clears all registrations between tests
Constructor Injection — Use optional constructor parameters to inject mocks in tests
💡 Tip: Override toString() in your registered classes to see meaningful details in the DevTools extension. By default, Dart's toString() only shows the type name and instance ID.
This package ships an Agent Skill for AI coding assistants
(Claude Code, Cursor, GitHub Copilot, Codex, Gemini CLI and others) in skills/get-it-expert/.
It teaches them the critical rules, common patterns and anti-patterns of get_it.
Install it into your project with the official Dart skills tool:
dart run skills@ get
For the ecosystem-wide skills (architecture guidance, feed/data-source patterns, overview)
and the skills of the other flutter_it packages run: