get_it 
π Complete documentation available at flutter-it.dev Check out the comprehensive docs with detailed guides, examples, and best practices!
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.
 
Learn more about the philosophy behind get_it β
π‘ New to service locators? Read Martin Fowler's classic article on Inversion of Control Containers and the Dependency Injection pattern or check out this detailed blog post on using service locators with Flutter.
Quick Start
Installation
Add to your pubspec.yaml:
dependencies:
  get_it: ^8.0.2
Basic Usage
import 'package:get_it/get_it.dart';
// Create a global instance (or use GetIt.instance)
final getIt = GetIt.instance;
// 1. Define your services
class ApiClient {
  Future<void> fetchData() async { /* ... */ }
}
class UserRepository {
  final ApiClient apiClient;
  UserRepository(this.apiClient);
}
// 2. Register them at app startup
void configureDependencies() {
  getIt.registerSingleton<ApiClient>(ApiClient());
  getIt.registerLazySingleton<UserRepository>(
    () => UserRepository(getIt<ApiClient>())
  );
}
// 3. Access from anywhere in your app
class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      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 β
 
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 β
 
Testing Support
get_it makes testing a breeze:
- Easy Mocking β Replace real implementations with mocks using 
allowReassignmentorreset() - Test Isolation β 
reset()clears all registrations between tests - Constructor Injection β Use optional constructor parameters to inject mocks in tests
 
// In tests
setUp(() {
  getIt.registerSingleton<ApiClient>(MockApiClient());
});
tearDown(() async {
  await getIt.reset();
});
Ecosystem Integration
get_it works independently β use it standalone for dependency injection in any Dart or Flutter project.
Want more? Combine with other packages from the flutter_it ecosystem:
- 
Optional: watch_it β Reactive state management built on get_it. Watch registered objects and rebuild widgets automatically.
 - 
Optional: command_it β Command pattern with loading/error states. Integrates seamlessly with get_it services.
 - 
Optional: listen_it β ValueListenable operators (map, where, debounce). Use with objects registered in get_it.
 
Remember: flutter_it is a construction set. Each package works independently. Pick what you need, combine as you grow.
Learn More
Documentation
- Getting Started β Installation, basic concepts, when to use what
 - Object Registration β All registration types, parameters, disposing
 - Scopes β Hierarchical scopes, shadowing, scope management
 - Async Objects β Async initialization, dependencies, 
allReady() - Testing β Unit tests, integration tests, mocking strategies
 - Advanced Topics β Named instances, multiple GetIt instances, runtime types
 - FAQ β Common questions and troubleshooting
 
Community & Support
- Discord β Get help, share ideas, connect with other developers
 - GitHub Issues β Report bugs, request features
 - GitHub Discussions β Ask questions, share patterns
 
Articles & Resources
- One to find them all: How to use Service Locators with Flutter β Comprehensive blog post on using get_it
 - Let's get this party started: Startup orchestration with GetIt β Deep dive into async initialization and startup orchestration
 - Martin Fowler on Service Locator Pattern β Classic article on IoC and DI patterns
 
Contributing
Contributions are welcome! Please read the contributing guidelines before submitting PRs.
License
MIT License - see LICENSE file for details.
Acknowledgements
Many thanks to Brian Egan and Simon Lightfoot for the insightful discussions on the API design.
Part of the flutter_it ecosystem β Build reactive Flutter apps the easy way. No codegen, no boilerplate, just code.