Skillshub flutter-dependency-injection
Standards for automated service locator setup using injectable and get_it. Use when configuring dependency injection with injectable and get_it in Flutter. (triggers: **/injection.dart, **/locator.dart, GetIt, injectable, singleton, module, lazySingleton, factory)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/flutter-dependency-injection" ~/.claude/skills/comeonoliver-skillshub-flutter-dependency-injection && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/flutter-dependency-injection/SKILL.mdsource content
Dependency Injection
Priority: P1 (HIGH)
Automated class dependency management using
get_it and injectable.
Structure
core/injection/ ├── injection.dart # Initialization & setup └── modules/ # Third-party dependency modules (Dio, Storage)
Implementation Guidelines
- Automated Registration: Use @injectable annotations; avoid manual registry calls.
- @LazySingleton: Default for repositories, services, and data sources (init on demand).
- Factory Registration: Use @injectable (Factory) for BLoCs to ensure state resets on every new instance/request. Do NOT use
for BLoCs.@Singleton() - Abstract Injection: Always register implementations as abstract interfaces (as: IService).
- Modules: Use @module for registering third-party instances (e.g., Dio, Hive,
).SharedPreferences - Constructor Injection: Use mandatory constructor parameters;
resolves them automatically.injectable - Test Mocks: Swap implementations in
using getIt.unregister<IService>() followed by getIt.registerLazySingleton<IService>(() => MockService()).setUp
Reference & Examples
For module configuration and initialization templates: See references/REFERENCE.md.
Anti-Patterns
- ❌
inside widgetgetIt<OrderRepository>()
— inject via constructor, not GetIt calls in UIbuild() - ❌
on a BLoC — BLoCs must use@Singleton()
(Factory) so state resets per instance@injectable - ❌ Injecting the concrete class:
— always inject the abstract interfaceOrderRepositoryImpl repo - ❌
in production code — usegetIt.registerLazySingleton<X>(() => X())
annotations; manual registration is only for tests@injectable
Related Topics
layer-based-clean-architecture | testing