flutter-di

Configures runtime dependency injection in Flutter apps using get_it and Riverpod providers.

Updated Jun 13, 2026
One-click install
npx skills add https://github.com/22Teikk/22Teikk-Agent-Skills-Hub --skill flutter-di-22teikk
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: flutter-di
Source: https://github.com/22Teikk/22Teikk-Agent-Skills-Hub/tree/main/packs/flutter/skills/flutter-di
Command: npx skills add https://github.com/22Teikk/22Teikk-Agent-Skills-Hub --skill flutter-di-22teikk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires get_it, riverpod.

What problem does it solve? Flutter apps need a consistent way to construct and share services, repositories, and SDK handles without hidden global state or untestable code. This Skill defines how to register and inject dependencies at runtime so classes stay testable and the object graph stays predictable. ## Core Features & Use Cases - get_it service locator setup: Register services with registerSingleton, registerLazySingleton, or registerFactory, and wire setupLocator() in main() before runApp(). - Riverpod provider variant: Use Riverpod providers for dependencies that need reactive state, widget lifecycle, or per-scope disposal in Riverpod projects. - Constructor injection patterns: Push dependencies through constructors instead of calling GetIt.instance inside class bodies, keeping classes testable without a locator. - Test isolation: Reset the locator with getIt.reset() or pushNewScope() in setUp and register fakes for clean, order-independent tests. - Use Case: When adding a new AnalyticsService to a Flutter app, register it as a lazy singleton in setupLocator(), inject it via constructor into the services that need it, and override it with a no-op fake in tests. ## Quick Start Ask the agent to set up dependency injection for your Flutter app by creating a setupLocator() function with get_it registrations and calling it in main() before runApp().

Frequently Asked Questions about flutter-di

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up dependency injection in Flutter with get_it?▼

Create a setupLocator() function that registers services with registerLazySingleton, registerSingleton, or registerFactory on GetIt.instance, then call it in main() before runApp(). Inject dependencies through constructors rather than calling GetIt.instance inside class bodies.

get_it vs Riverpod for dependency injection in Flutter?▼

Use get_it for pure, stateless services consumed imperatively, such as API clients or analytics wrappers. Use Riverpod providers only in projects already using Riverpod for state, when the dependency needs reactive state, widget lifecycle, or per-scope disposal.

What is the difference between registerSingleton and registerLazySingleton in get_it?▼

registerSingleton creates the instance eagerly at registration time, while registerLazySingleton creates it on first access. Lazy registration is the default choice because it keeps startup fast and avoids order-of-initialization crashes.

How do I reset get_it between tests in Flutter?▼

Call getIt.reset() in setUp to unregister everything, then register fakes for each test. Alternatively use pushNewScope() and popScope() to isolate nested registrations while keeping a shared base set.

Can I call GetIt.instance inside a Riverpod provider?▼

No. Reaching into GetIt.instance inside a provider body bypasses Riverpod's ProviderScope override mechanism, making tests unable to substitute fakes. Expose the service through a provider and use ref.watch instead.

When should I not use get_it in a Flutter app?▼

Do not use get_it for reactive state holders or view models that widgets watch; that belongs to the state management layer such as Bloc or Riverpod. Also avoid it for build configuration like flavors, pubspec dependencies, or codegen.