ResponsiveConstraints class

A widget that applies different BoxConstraints based on the current screen type — allowing precise control over min/max width and height per device category.

Performance Design

  • Single ScreenType lookup per build — O(1)
  • No LayoutBuilder — constraints are applied via a simple ConstrainedBox
  • Fallback chain avoids null checks: largeDesktop → desktop → tablet → mobile

Example

ResponsiveConstraints(
  mobile: BoxConstraints(maxWidth: 350, minHeight: 100),
  tablet: BoxConstraints(maxWidth: 500, minHeight: 120),
  desktop: BoxConstraints(maxWidth: 800, minHeight: 150),
  child: ProductCard(),
)

With Alignment

ResponsiveConstraints(
  alignment: Alignment.center,
  mobile: BoxConstraints(maxWidth: 350),
  desktop: BoxConstraints(maxWidth: 600),
  child: LoginForm(),
)
Inheritance

Constructors

ResponsiveConstraints({Key? key, required Widget child, required BoxConstraints mobile, BoxConstraints? tablet, BoxConstraints? smallDesktop, BoxConstraints? desktop, BoxConstraints? largeDesktop, AlignmentGeometry? alignment, bool scaleConstraints = false})
Creates a ResponsiveConstraints widget.
const

Properties

alignment → AlignmentGeometry?
Optional alignment of the constrained child within its parent. If null, no Align wrapper is added.
final
child → Widget
The child widget to constrain.
final
desktop → BoxConstraints?
Constraints for desktop screens. Falls back down the chain.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
largeDesktop → BoxConstraints?
Constraints for large desktop screens. Falls back down the chain.
final
mobile → BoxConstraints
Constraints for mobile/watch screens. Required as the fallback.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scaleConstraints → bool
Whether to scale the constraint values using Scalify's scale factor. Default: false (uses raw pixel values).
final
smallDesktop → BoxConstraints?
Constraints for small desktop screens. Falls back to tablet → mobile.
final
tablet → BoxConstraints?
Constraints for tablet screens. Falls back to mobile.
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
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