RearchInjection<W extends RearchInjection<W, Data>, Data> class abstract

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).

Inheritance
Annotations
  • @experimental

Constructors

RearchInjection.new({required Widget child, Key? key})
Injects some state to descendants in the Widget tree.
const

Properties

child Widget
The widget below this widget in the tree.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context, WidgetHandle use) → Data
Creates the data to pass down the widget tree below the RearchInjection.
createElement() Element
Inflates this configuration to a concrete instance.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

maybeOf<Injection extends RearchInjection<Injection, T>, T>(BuildContext context) → T?
The state from the closest instance of the provided RearchInjection that encloses the given context, if any.
of<Injection extends RearchInjection<Injection, T>, T>(BuildContext context) → T
The state from the closest instance of the provided RearchInjection that encloses the given context.