dependency_injector 0.0.2 copy "dependency_injector: ^0.0.2" to clipboard
dependency_injector: ^0.0.2 copied to clipboard

outdated

A dependency injection system for Flutter that automatically calls a dispose method if there is one.

dependency_injector #

A dependency injection system for Flutter that automatically calls a dispose method if there is one.

Getting Started #

Documentation coming soon.

For now you can look at the source code of the example and run it.

Basic example

import 'package:flutter/material.dart';
import 'package:dependency_injector/dependency_injector.dart';

class SomeService {
  final Repository repository = inject();
}

class Repository {
  String getData() => 'Hello world.';
}

final services = [
  Transient(() => SomeService()),
  Singleton(() => Repository()),
];

void main() {
  runApp(RootInjector(
    services: services,
    child: Injector(() => MyApp()),
  ));
}

class MyApp extends StatelessWidget {
  MyApp({Key key}) : super(key: key);

  final SomeService someService = inject();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
        body: Center(child: Text(someService.repository.getData())),
      ),
    );
  }
}
6
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A dependency injection system for Flutter that automatically calls a dispose method if there is one.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, meta

More

Packages that depend on dependency_injector