ReactterProvider<T extends Object?> class
abstract
A Widget that provides an instance of T
type to widget tree
that can be access through the methods BuildContext extension.
ReactterProvider<AppController>(
() => AppController(),
builder: (appController, context, child) {
return Text("StateA: ${appController.stateA.value}");
},
)
Use id
property to identify the T
instance.
Use child property to pass a Widget which to be built once only.
It will be sent through the builder
callback, so you can incorporate it
into your build:
ReactterProvider<AppController>(
() => AppController(),
child: Text("This widget build only once"),
builder: (context, child) {
final appController = context.watch<AppController>();
return Column(
children: [
Text("state: ${appController.stateA.value}"),
child,
],
);
},
)
RECOMMENDED: Dont's use Object with constructor parameters to prevent conflicts.
NOTE: ReactterProvider is a "scoped". This mean that ReactterProvider exposes the instance of
T
type defined on first parameter(InstanceContextBuilder) through the BuildContext in the widget subtree:ReactterProvider<AppController>( () => AppController(), builder: (appController, context, child) { return OtherWidget(); } ); class OtherWidget extends StatelessWidget { ... Widget build(context) { final appController = context.use<AppController>(); return Column( children: [ Text("StateA: ${appController.stateA.value}"), Builder( builder: (context){ context.watch<AppController>((inst) => [inst.stateB]); return Text("StateB: ${appController.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:
- ReactterProviders, a widget that allows to use multiple ReactterProvider.
- Implemented types
Constructors
-
ReactterProvider(InstanceBuilder<
T> instanceBuilder, {Key? key, String? id, InstanceManageMode mode = InstanceManageMode.builder, bool init = false, Widget? child, InstanceContextBuilder<T> ? builder}) -
A Widget that provides an instance of
T
type to widget tree that can be access through the methods BuildContext extension.factory
Properties
- child → Widget
-
The widget below this widget in the tree.
finalinherited
- 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
-
createElement(
) → ReactterProviderElement< T> -
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}) → 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.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
contextOf<
T extends Object?> (BuildContext context, {String? id, ListenStates< T> ? listenStates, bool listen = true}) → T -
Returns an instance of
T
and sets the BuildContext to listen for when it should be re-rendered.