ResponsiveScope class

Establishes the responsive device-class context for its subtree.

Reads MediaQuery.sizeOf(context).width, classifies it via classify, and publishes the result through an inherited _ResponsiveData so that ResponsiveContext.deviceSize / ResponsiveContext.responsive resolve.

Place this above the subtree that must not rebuild on resize, and pass a stable child reference: the segment-only-rebuild guarantee (BEH-05) depends on the same child instance being forwarded across resizes. The scope itself may rebuild per-pixel as the window changes, but the subtree is preserved as long as child is unchanged — so prefer a const child:

runApp(const ResponsiveScope(child: MyApp()));

Why it is a StatefulWidget. The widget carries no runtime state — it is stateful purely so a debug-only diagnostic can track the child across rebuilds. If an ancestor rebuilds the scope on every resize frame while constructing the child inline (an unstable reference), the whole subtree rebuilds per-pixel and the segment-only guarantee is silently lost. To make that loud, build watches for the failure's exact signature — the child instance changing on a rebuild that did not change the device class — and after _kUnstableChildWarnThreshold consecutive such rebuilds emits a single debugPrint. It checks identity, not const-ness, so a non-const-but-stable child is fine; the entire check is inside an assert and costs nothing in release.

Top-level placement (above MaterialApp) is valid: runApp wraps the app in a root View that supplies a MediaQuery via MediaQuery.fromView, so the scope always resolves one. The one caveat: a runWidget / multi-view bootstrap must ensure a View / MediaQuery sits above the scope.

Inheritance
Available extensions

Constructors

ResponsiveScope({Key? key, required Widget child})
const

Properties

child Widget
The subtree that reads the device class. Pass a stable reference (ideally const) to preserve it across resizes.
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

Methods

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

Available on Widget, provided by the AppUpdateDebugExtension extension

Wraps this widget with debug controls if in debug mode

Operators

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