RearchInjection<W extends RearchInjection<W, Data> , Data> constructor
const
RearchInjection<W extends RearchInjection<W, Data> , Data> ({})
Injects some state to descendants in the Widget tree.
Here's a simple example of injecting some int state into the widget tree:
class MyInjection extends RearchInjection<MyInjection, ValueWrapper<int>> {
const MyInjection({required super.child, super.key});
@override
ValueWrapper<int> build(BuildContext context, WidgetHandle use) {
return use.data(0);
}
static ValueWrapper<int> of(BuildContext context) =>
RearchInjection.of<MyInjection, ValueWrapper<int>>(context);
static ValueWrapper<int>? maybeOf(BuildContext context) =>
RearchInjection.maybeOf<MyInjection, ValueWrapper<int>>(context);
}
You can think of a RearchInjection as a RearchConsumer wrapped around an InheritedWidget (as that is exactly how it is implemented), but with minimal boilerplate.
WARNING
This class is experimental since I am not yet 100% sold on the API. It's a little too verbose still for my tastes (and unfortunately, the development of macros was halted).
Implementation
const RearchInjection({required this.child, super.key});