dartin 0.1.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 78

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.2
  

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<T>**: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([
  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 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

[0.1.2] - 2019.04.10

  • correct readme

[0.1.1] - 2019.04.10

  • correct readme

[0.1.0] - 2019.03.23

  • publish version 0.1.0
  • add example

[0.0.1] - 2019.03.22

  • publish version 0.0.1

example/lib/main.dart

import 'package:dartin/dartin.dart';

import 'dummy.dart';

//constant scope
const other = DartInScope('other');
const params = DartInScope('params');

final dummy1 = Dummy(1);
final dummy2 = Dummy(2);

//define module
final m = Module([
  single<Dummy>(dummy1),
])
  ..withScope(other, [
    single<Dummy>(dummy2),
  ])
  ..withScope(params, [
    factory<Dummy>(({params}) => Dummy(params.get(0))),
  ]);

main() {

  startDartIn([m]);

  //default
  final value1 = inject<Dummy>();
  //scope
  final value2 = inject<Dummy>(scope: other);
  //parameters
  final value3 = inject<Dummy>(scope: params, params: [3]);

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dartin: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dartin/dartin.dart';
  
Version Uploaded Documentation Archive
0.1.2 Apr 10, 2019 Go to the documentation of dartin 0.1.2 Download dartin 0.1.2 archive
0.1.1 Apr 10, 2019 Go to the documentation of dartin 0.1.1 Download dartin 0.1.1 archive
0.1.0 Mar 23, 2019 Go to the documentation of dartin 0.1.0 Download dartin 0.1.0 archive
0.0.1 Mar 22, 2019 Go to the documentation of dartin 0.0.1 Download dartin 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Apr 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test