Skip to content
pubscout

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.

WASM-readyRock solid
$ flutter pub add get_it
Source repository

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.

  • klizma

    A lightweight DI container for Dart with singleton and named factory support.

  • toor

    Compile-time safe and easy to manage service locators for Dart and Flutter.

Works with

Packages commonly used together with get_it: ones it builds on, ones built on it, and its own family.