flutter_koin
1.1.0, released 4 weeks ago by an unverified publisher
A lightweight dependency injection library for Flutter with code generation and scopes.
What it does
Generates dependency injection registrations from annotations like @RootScoped, @Scoped, and @Factory. It offers constructor injection, interface bindings, and scope-aware lifecycles for Flutter apps.
AI-written summary of version 1.1.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want annotation-based dependency injection with code generation.
- Your app requires root and feature-scoped lifecycles with automatic disposal.
- You prefer constructor injection for required positional and named parameters.
Skip it when
- You require asynchronous factories or asynchronous dependency resolution.
- You need to inject optional constructor parameters automatically.
Strengths
- No runtime reflection due to build_runner code generation.
- Scope-aware lifecycles integrated with Flutter widgets via KoinScopeHost.
- Supports interface bindings using bindAs.
Weaknesses
- Generated factories and dependency resolution are strictly synchronous.
- Does not support generic classes or constructors with optional parameters for injection.
- Root-scoped dependencies cannot depend on feature-scoped dependencies.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 3
Add flutter_koin and build_runner as a dev dependency, then run the build_runner command to generate part files.
import 'package:flutter_koin/flutter_koin.dart';
part 'app_di.koin.dart';
@RootScoped()
class ApiClient {
String get status => 'Connected';
}Alternatives
Packages that do the same job and could replace flutter_koin.
- get_it
If you prefer a service locator without code generation or part files.
89Compare - injectable
If you need a more feature-complete annotation-based DI framework built on top of get_it.
78Compare
Works with
Packages commonly used together with flutter_koin: ones it builds on, ones built on it, and its own family.
- analyzerflutter_koin depends on itPerforms static analysis of Dart code for tool integration and embedding.
- buildflutter_koin depends on itPackage for authoring build_runner compatible code generators.
- source_genflutter_koin depends on itSource code generation builders and utilities for the Dart build system.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.