vader_flutter 1.2.0
vader_flutter: ^1.2.0 copied to clipboard

A Flutter implementation of the Vader package with widgets and Provider wrap around

example/example.dart

import 'package:flutter/material.dart';
import 'package:vader_di/vader.dart';
import 'package:vader_flutter/vader_flutter.dart';

void main() {
  runApp(
    ModuleValueInjector<String>(
      valueToResolve: 'Hello world',
      child: DependentWidget<String>(
        builder: (val) => Text(val.toString()),
      ),
    )
  );
}

class TestableWidget<T extends Object> extends StatelessWidget {
  final T valueToResolve;

  const TestableWidget({
    Key key,
    this.valueToResolve
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ModuleValueInjector(
      valueToResolve: valueToResolve,
      child: DependentWidget<T>(
        builder: (val) => Text(val.toString()),
      ),
    );
  }
}

class ModuleValueInjector<T> extends ModuleInjector {
  final Widget child;
  final T valueToResolve;

  ModuleValueInjector({
    Key key,
    @required this.child,
    @required this.valueToResolve
  }) : super(key: key);

  @override
  void configure(DiContainer container) {
    container.bind<T>().toValue(valueToResolve);
  }
}
4
likes
120
pub points
32%
popularity

Publisher

Unknown

A Flutter implementation of the Vader package with widgets and Provider wrap around

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

Dependencies

flutter, meta, provider, vader_di

More

Packages that depend on vader_flutter