CubeScope class

Provides a CubeContainer to its widget subtree.

CubeScope creates a new child CubeContainer scoped under the nearest ancestor container (or CubePod.root if there is none). It exposes the container to all descendants via CubeScope.of and context.get<T>().

Basic Usage

CubeScope(
  overrides: (c) {
    c.register<HomeViewModel>(
      (c) => HomeViewModel(c.get<UserRepo>()),
      scope: Scope.scoped,
    );
  },
  child: HomeScreen(),
)

Lifecycle

The container is created in State.didChangeDependencies and disposed automatically when the CubeScope widget is removed from the tree. All Disposable instances registered in the scope are disposed with it.

Inheritance

Constructors

CubeScope({Key? key, required Widget child, String? name, void overrides(CubeContainer)?})
const

Properties

child Widget
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?
An optional debug name for this scope, visible in DevTools.
final
overrides → void Function(CubeContainer)?
An optional callback to register or override dependencies in the new child container before it is exposed to the subtree.
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<CubeScope>
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, Widget child) Widget
Wraps child in the current scope's CubeScopeInherited without creating a new container. Useful for preserving scope across navigation or overlay boundaries.
maybeOf(BuildContext context) → CubeContainer?
Returns the nearest CubeContainer in the widget tree, or null if no CubeScope ancestor exists.
of(BuildContext context) → CubeContainer
Returns the nearest CubeContainer in the widget tree.
runAsAmbient(CubeContainer container, Widget child) Widget
Exposes an existing container to child without creating a new scope.