MinProvider<T extends ChangeNotifier> class
A standalone provider widget that manages the lifecycle (onInit, onReady, and dispose)
of a state manager instance.
How to use:
Registering the provider:
MinProvider(
create: () => MyViewModel(),
child: const MyView(),
)
or
MinProvider(
create: () => MyViewModel(),
child: const MyView(),
)
//or usage with tag
MinProvider(
create: () => MyViewModel(),
tag: 'page1',
child: const MyView(),
)
Accessing state inside build() (Rebuilds on change):
final notifier = MinProvider.watch<MyNotifier>(context);
//with tag
final notifier = MinProvider.watch<MyNotifier>(context, tag: 'page1');
Accessing state for callbacks/methods (No rebuilds):
final notifier = MinProvider.read<MyNotifier>(context);
//usage with tags
final notifier = MinProvider.read<MyNotifier>(context, tag: 'page1');
controller.doSomething();
//or use provider_extensions
final notifier = context.read<MyNotifier>(tag: 'page1');
final notifier = context.watch<MyNotifier>(tag: 'page1');
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- MinProvider
Constructors
- MinProvider({Key? key, required T create(), String? tag, required Widget child})
-
Creates a MinProvider to inject a single controller
into the widget tree.
const
Properties
- child → Widget
-
The widget below this provider in the tree, which will have
access to the provided controller.
final
- create → T Function()
-
A function or instance that creates the notifier to be provided.
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
- tag → String?
-
link a instance notifier a one tag
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< MinProvider< T> > -
Creates the mutable state for this widget at a given location in the tree.
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
-
read<
T extends ChangeNotifier> (BuildContext context, {String? tag}) → T - Accesses the controller without subscribing to changes.
-
watch<
T extends ChangeNotifier> (BuildContext context, {String? tag}) → T - Accesses the controller and subscribes the context to changes.