Skip to main content

Flutter

Installation

Add the wiretap_flutter package to your pubspec.yaml by running flutter pub add wiretap_flutter.

Injecting values

You can inject values pretty much the same like you would in a dart-only application by using the .inject() extension method on BuildContext:

class ExampleWidget extends StatelessWidget {
Widget build(BuildContext context) {
final fooService = context.inject(fooServiceToken);
return Text(fooService.text());
}
}

WiretapScope

To be able to inject anything from BuildContext you would typically wrap your Application in a WiretapScope to allow access in its children like so:

void main() {
runApp(WiretapScope(
providers: [
// place your providers here
],
child: MaterialApp(),
));
}

If you want to, you can also take control of creating a WiretapContext yourself:

void main() {
final wiretapContext = WiretapContext(providers: [
// place your providers here
]);
runApp(WiretapScope(
wiretapContext: wiretapContext,
child: MaterialApp(),
));
}