Search packages, repositories and app categories

Package detailsv0.1.5

dartin

A pragmatic lightweight dependency injection framework for Flutter developers.

30-day downloads
100
Likes
8
Pub points
40

Install package

flutter pub add dartin

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

Dartin is a lightweight, pragmatic dependency injection framework designed for Flutter developers. It simplifies the management of dependencies in Flutter applications by providing a clean and efficient way to register and resolve dependencies. With minimal boilerplate and intuitive syntax, Dartin enables easy integration into existing projects without adding complexity. It supports both simple and advanced use cases, making it ideal for apps ranging from small prototypes to large-scale applications. The framework emphasizes developer experience and performance, ensuring fast startup times and reliable dependency resolution.

Use cases

  • Simple app dependency management
  • Large-scale Flutter application architecture
  • Testing with mocked dependencies
  • Rapid prototyping
  • Modular app development
  • State management integration

Key features

  • Minimal boilerplate
  • Easy setup and configuration
  • Supports singleton and transient instances
  • Built-in support for testing
  • Lightweight footprint
  • Intuitive API design

Suitable for

  • Flutter beginners seeking simple DI
  • Experienced developers needing lightweight DI
  • Teams building modular Flutter apps
  • Projects requiring testable dependency structure
  • Apps with evolving dependency needs

Considerations

  • Limited documentation compared to larger frameworks
  • No built-in state management
  • Not suitable for very complex dependency graphs
  • Community size smaller than alternatives
  • Requires manual setup for advanced features

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

dartin

A pragmatic lightweight dependency injection framework for Flutter developers.

A light container inspired by flutter-provide and koin.

more examples see mvvm_flutter.

Setup
dependencies:
  dartin: ^0.1.5
  
Key methods
  • single:Creates a provider which will initialize using the [_DartInFunction] the first time the value is requested.

  • factory:Creates a provider that provides a new value using the [_DartInFunction] for each requestor of the value.

  • inject:get T from dartIns by T.runtimeType and params

more informations see dartin.dart.

Getting Started
  1. declare dartin modules
//scope should always be initialized as a static const and passed around.
const test = DartInScope('test');

final viewModelModule = Module([
  factory<HomeProvide>(({params}) => HomeProvide(params.get(0), get<GithubRepo>())),
])
  ..withScope(test , [
    ///other scope
   factory<HomeProvide>(({params}) => HomeProvide(params.get(0), get<GithubRepo>())),
  ]);

final repoModule = Module([
  single<GithubRepo>(({params}) => GithubRepo(get<GithubService>())),
]);

final remoteModule = Module([
  single<GithubService>(({params}) => GithubService()),
]);

final appModule = [viewModelModule, repoModule, remoteModule];

  1. Start dartin
void main() {
  startDartIn(appModule);
  runApp(MyApp());
}
  1. inject
//default
final service = inject<GithubService>();
//pass parameters
final test = inject<HomeProvide>(params: ['title']);
//different scope
final test = inject<HomeProvide>(scope:test,params: ['title']);

DartIn is easy to use, and still improving.

🍺 welcome to fork and pull request。

Article

【Medium】:DartIn:A pragmatic lightweight dependency injection framework for Flutter developers

【简书】:为Flutter而生的轻量级依赖检索容器—DartIn

【掘金】:为Flutter而生的轻量级依赖检索容器—DartIn

Licence

BSD

Categories

Source repository

Projects using this package