LScope class

A widget that creates a LevitScope tied to the widget tree.

Use LScope to provide dependencies for a specific subtree. The scope is automatically closed when the widget is unmounted.

// Example usage:

LScope(
  dependencyFactory: (scope) => scope.put<MyController>(() => MyController()),
  child: const MyPage(),
)
Inheritance

Constructors

LScope({Key? key, LScopeDependencyFactory? dependencyFactory, required Widget child, String? name, List<Object?>? args})
Creates a widget-tree-bound dependency scope.
const

Properties

args List<Object?>?
Optional dependency keys for reactive re-initialization.
final
child Widget
The widget subtree that will have access to this scope.
final
dependencyFactory LScopeDependencyFactory?
An optional factory to register dependencies in this scope.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
name String?
A descriptive name for the scope (used in profiling and logs).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<LScope>
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

capture(BuildContext context, {required Widget child}) Widget
Captures the nearest LevitScope from context and re-provides it to another subtree.
lazyPut<S>(S builder(), {Key? key, required Widget child, String? name, String? tag, bool permanent = false, bool isFactory = false, List<Object?>? args}) LScope
A shorthand for creating a scope and registering a lazy dependency.
lazyPutAsync<S>(Future<S> builder(), {Key? key, required Widget child, String? name, String? tag, bool permanent = false, bool isFactory = false, List<Object?>? args}) LScope
A shorthand for creating a scope and registering an async lazy dependency.
of(BuildContext context, {bool listen = false}) LevitScope?
The nearest LevitScope from the widget tree.
put<S>(S builder(), {Key? key, required Widget child, String? name, String? tag, bool permanent = false, List<Object?>? args}) LScope
A shorthand for creating a scope and immediately registering a dependency.
runBridged<R>(BuildContext context, R builder()) → R
Executes builder within the Zone of the nearest LScope.