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

outdated

A simple and modular dependency injection system without using reflection.

example/example.dart

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

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

class MyModule extends Module {
  @override
  void configure(Binder binder) {
    binder
      ..bindSingleton(Object());
  }
}

class SomeWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final injector = InjectorWidget.of(context);
    final apiKey = injector.get(name: "api_key");
    print(apiKey);
    return Container();
  }
}
2
likes
0
pub points
27%
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