Skip to content
Back to skills

Flutter Dependency Injection

ASecurity

Register it in three layers, following the skill’s DI rules: 1. Put third-party dependencies like `Dio` and Hive objects behind an `@module` 2. Register the repository as a `@LazySingleton`, because repositories should usually be shared and initialized on demand 3. Inject the repository through its abstraction, not the concrete class Example: ```dart import 'package:dio/dio.dart'; import 'package:hive/hive.dart'; import 'package:injectable/injectable.dart'; abstract class IOrderRepository { F...

  • 584 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
developmentapi

Works with

  • api

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill flutter-dependency-injection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Flutter Dependency Injection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Flutter Dependency Injection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-flutter-dependency-injection-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-dependency-injection-agent-skills-standard)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
Register it in three layers, following the skill’s DI rules:

1. Put third-party dependencies like `Dio` and Hive objects behind an `@module`
2. Register the repository as a `@LazySingleton`, because repositories should usually be shared and initialized on demand
3. Inject the repository through its abstraction, not the concrete class

Example:

```dart
import 'package:dio/dio.dart';
import 'package:hive/hive.dart';
import 'package:injectable/injectable.dart';

abstract class IOrderRepository {
  Future<void> submitOrder();
}

class OrderEntity {}

@module
abstract class DataModule {
  @lazySingleton
  Dio get dio => Dio(
        BaseOptions(baseUrl: 'https://api.example.com'),
      );

  @preResolve
  Future<Box<OrderEntity>> get orderBox async {
    return await Hive.openBox<OrderEntity>('orders');
  }
}

@LazySingleton(as: IOrderRepository)
class OrderRepository implements IOrderRepository {
  final Dio _dio;
  final Box<OrderEntity> _orderBox;

  OrderRepository(this._dio, this._orderBox);

  @override
  Future<void> submitOrder() async {
    // use _dio for remote calls
    // use _orderBox for local persistence/cache
  }
}
```

Why this matches the skill:

- `@module` is the right place for external dependencies you cannot annotate directly
- `@LazySingleton` is the default choice for repositories and data sources
- `as: IOrderRepository` keeps consumers dependent on the interface instead of the implementation
- constructor injection keeps the dependency graph explicit and testable

If you want a cleaner boundary around Hive, an even better version is to wrap the box in a local data source and inject that instead of injecting `Box<OrderEntity>` directly:

```dart
abstract class IOrderLocalDataSource {}

@LazySingleton(as: IOrderLocalDataSource)
class HiveOrderLocalDataSource implements IOrderLocalDataSource {
  final Box<OrderEntity> box;
  HiveOrderLocalDataSource(this.box);
}

@LazySingleton(as: IOrderRepository)
class OrderRepository implements IOrderRepository {
  final Dio _dio;
  final IOrderLocalDataSource _local;

  OrderRepository(this._dio, this._local);
}
```

That version is usually easier to mock and keeps Hive-specific details out of the repository contract.

After adding the annotations, regenerate the injectable code so `get_it` picks up the new registrations. The key idea is: module for `Dio` and Hive, `@LazySingleton` for the repository, and inject the interface everywhere else.

Files in this skill

  • eval-1.baseline.md2.1 KB
  • eval-1.with-skill.md2.4 KB
  • eval-2.baseline.md2 KB
  • eval-2.with-skill.md1.8 KB
  • eval-3.baseline.md2.5 KB
  • eval-3.with-skill.md2.4 KB
  • trigger-1.md147 B
  • trigger-2.md138 B
  • trigger-3.md161 B
  • trigger-4.md154 B
  • trigger-5.md138 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.