Overview
Injectable_generator is a code generation tool for Flutter that simplifies dependency injection using the get_it service locator. Inspired by Angular, Guice, and inject.dart, it enables developers to define dependencies declaratively with annotations. The generator automatically creates boilerplate code for registering and resolving dependencies, improving maintainability and reducing runtime errors. It integrates seamlessly into Flutter projects across macOS, Windows, and Linux platforms.
Use cases
- Automating dependency registration
- Simplifying unit testing with mocked dependencies
- Reducing boilerplate in large-scale apps
- Enabling clean architecture with dependency injection
- Managing complex dependency graphs
Key features
- Annotation-based dependency definition
- Automatic code generation for get_it
- Support for lazy and singleton instances
- Type-safe dependency resolution
- Integration with build_runner
Suitable for
- Large Flutter applications
- Teams using clean architecture
- Developers seeking reduced boilerplate
- Projects requiring testable dependency management
- Apps with complex dependency structures
Considerations
- Requires build_runner setup
- Needs understanding of get_it
- May increase build time
- Not suitable for simple one-off projects
- Limited runtime flexibility compared to manual registration