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

outdated

A simple and modular dependency injection system without using reflection.

pub package

Simple package ease the use of the dependencies with Flutter leveraging the power of InheritedWidget.

Usage #

class SomeRootWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return InjectorWidget.bind(
      binderFunc: (binder) {
        binder
          ..install(MyModule())
          ..bindSingleton("api123", name: "api_key");
      },
      child: SomeWidget()
    );
  }
}

Alternatively you can build the injector using the InjectorBuilder and pass it in like this:

class SomeRootWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return InjectorWidget(
      injector: injector,
      child: SomeWidget()
    );
  }
}

You can later refer to the injector like any other InheritedWidget.

class SomeWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final injector = InjectorWidget.of(context);
    final apiKey = injector.get(name: "api_key");
    return SomeContainerNeedingTheKey(apiKey);
  }
}
2
likes
0
pub points
10%
popularity

Publisher

unverified uploader

A simple and modular dependency injection system without using reflection.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dependencies, flutter

More

Packages that depend on dependencies_flutter