ReactterProvider<T extends ReactterContext> class

A StatelessWidget that provides a ReactterContext's instance of T to widget tree that can be access through the BuildContext.

ReactterProvider<AppContext>(
  () => AppContext(),
  builder: (appContext, context, child) {
    return Text("StateA: ${appContext.stateA.value}");
  },
)

Use id property for create a different instances of ReactterContext.

CONSIDER: Dont's use ReactterContext with constructor parameters to prevent conflicts.

CONSIDER Use child property to pass a Widget that you want to build it once. The ReactterProvider pass it through the builder callback, so you can incorporate it into your build:

ReactterProvider<AppContext>(
  () => AppContext(),
  child: Text("This widget build only once"),
  builder: (context, child) {
    final appContext = context.watch<AppContext>();

    return Column(
      children: [
        Text("state: ${appContext.stateA.value}"),
        child,
      ],
    );
  },
)

NOTE: ReactterProvider is a "scoped". This mean that ReactterProvider exposes the ReactterContext defined on first parameter(InstanceBuilder) through the BuildContext in the widget subtree:

ReactterProvider<AppContext>(
  () => AppContext(),
  builder: (appContext, context, child) {
    return OtherWidget();
  }
);

class OtherWidget extends StatelessWidget {
  ...
  Widget build(context) {
     final appContext = context.use<AppContext>();

     return Column(
      children: [
        Text("StateA: ${appContext.stateA.value}"),
        Builder(
          builder: (context){
            context.watch<AppContext>((ctx) => [ctx.stateB]);

            return Text("StateB: ${appContext.stateB.value}");
          },
        ),
      ],
    );
  }
}

In the above example, stateA remains static while the Builder is rebuilt according to the changes in stateB. Because the Builder's context kept in watch of stateB.

See also:

Inheritance

Constructors

ReactterProvider(ContextBuilder<T> instanceBuilder, {Key? key, String? id, bool init = false, Widget? child, InstanceBuilder<T>? builder})
const

Properties

builder → InstanceBuilder<T>?
Method which has the render logic
final
child → Widget
The widget below this widget in the tree.
finalinherited
hashCode → int
The hash code for this object.
no setterinherited
id → String?
final
init → bool
Create the instance defined on firts parameter _instanceBuilder when UseContext is called.
final
instanceBuilder → ContextBuilder<T>
Create a instances of ReactterContext class
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType → Type
This is a hack to save it and find it with the id distinction in _inheritedWidgets of Element using the helper functions of BuildContext like getElementForInheritedWidgetOfExactType.
no setteroverride

Methods

build(BuildContext context) → Widget
createElement() → ReactterProviderElement<ReactterContext?>
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
updateShouldNotify(covariant InheritedWidget oldWidget) → bool
Whether the framework should notify widgets that inherit from this widget.
override

Operators

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

Static Methods

contextOf<T extends ReactterContext?>(BuildContext context, {String? id, ListenStates<T>? listenStates, ListenHooks<T>? listenHooks, bool listen = true}) → T
Returns an instance of T and sets the BuildContext to listen for when it should be re-rendered.