flutter-di-and-build

Configures Flutter dependency injection, pubspec dependencies, flavors, build_runner codegen, and GitHub Actions CI.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Flutter projects often suffer from scattered dependency versions, global singletons that break testability, missing codegen steps in CI, and secrets leaked through --dart-define. This Skill standardizes the build-side setup of a Flutter app so dependency management, DI wiring, flavors, and CI follow one consistent, verifiable pattern. ## Core Features & Use Cases - Dependency management: Structures pubspec.yaml with caret ranges for libraries, exact pins for codegen tools, and correct dependencies vs dev_dependencies separation. - DI and flavors: Wires get_it registrations via setupLocator() before runApp, supports BLoC MultiBlocProvider or a Riverpod variant, and configures --dart-define environments with per-flavor entry points. - Codegen and CI: Sets up build_runner for freezed/json_serializable/drift and a GitHub Actions workflow running pub get, codegen, analyze, test, and release builds. - Use Case: When adding a new package or wiring a release pipeline, apply this Skill to update pubspec.yaml, register the dependency in get_it, and extend the GitHub Actions workflow so clean checkouts build successfully. ## Quick Start Set up my Flutter project's pubspec dependencies, get_it locator, dev and prod flavors with --dart-define, and a GitHub Actions CI workflow that runs build_runner, analyze, and tests.

Frequently Asked Questions about flutter-di-and-build

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?▼

Register every object with a lifecycle once in get_it inside a setupLocator() function, then call it at the top of main() before runApp(). Use registerLazySingleton for app-lifetime services and registerFactory for per-scope instances, and call getIt.reset() in tests to inject fakes.

How do I configure Flutter flavors with --dart-define?▼

Keep a single lib/main.dart that reads keys like API_BASE and FLAVOR via String.fromEnvironment with sane defaults. Pass values at runtime with flutter run --dart-define=FLAVOR=dev, and add per-flavor entry shims like main_dev.dart only when native config differs.

Should I use get_it with BLoC or Riverpod for Flutter DI?▼

The default pattern pairs get_it registrations with flutter_bloc, exposing Blocs via MultiBlocProvider and repositories via RepositoryProvider. Projects declaring flutter_riverpod instead author providers with riverpod_generator and override them in tests with ProviderScope, but never mix both DI seams in one feature subtree.

Why does my Flutter release build fail in CI but work locally?▼

Clean checkouts fail when build_runner codegen was never run, since generated files like *.g.dart and *.freezed.dart are missing. Run dart run build_runner build --delete-conflicting-outputs in CI before flutter build, or commit the generated files.

Is it safe to pass API keys with --dart-define in Flutter?▼

No, --dart-define values are compiled into the binary and recoverable from release APKs or IPAs. Use runtime config fetched from a backend or platform secure storage like flutter_secure_storage for anything sensitive.