dartin 0.0.1 copy "dartin: ^0.0.1" to clipboard
dartin: ^0.0.1 copied to clipboard

outdated

A pragmatic lightweight dependency injection framework for Flutter developers.

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:
  flutter:
    sdk: flutter
        
  dartin:0.0.1

Key methods #

  • single:Creates a provider with the value provided to it.

  • lazy: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 infomations 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>())),
])
  ..addOthers(test , [
    ///other scope
   factory<HomeProvide>(({params}) => HomeProvide(params.get(0), get<GithubRepo>())),
  ]);

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

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

final appModule = [viewModelModule, repoModule, remoteModule];

  1. Start dartin

void main() {
  startDartIn(appModule);
  runApp(MyApp());
}
  1. inject

//default
final service = inject<GithubService>();
//pass paramaters
final test = inject<HomeProvide>(params: ['title']);
//different scope
final test = inject<HomeProvide>(scope:test,params: ['title']);

🍺 welcome to fork and pull request。

Licence #

BSD

8
likes
0
pub points
70%
popularity

Publisher

unverified uploader

A pragmatic lightweight dependency injection framework for Flutter developers.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on dartin