ConstraintsTransformBox class

A container widget that applies an arbitrary transform to its constraints, and sizes its child using the resulting BoxConstraints, optionally clipping, or treating the overflow as an error.

This container sizes its child using a BoxConstraints created by applying constraintsTransform to its own constraints. This container will then attempt to adopt the same size, within the limits of its own constraints. If it ends up with a different size, it will align the child based on alignment. If the container cannot expand enough to accommodate the entire child, the child will be clipped if clipBehavior is not Clip.none.

In debug mode, if clipBehavior is Clip.none and the child overflows the container, a warning will be printed on the console, and black and yellow striped areas will appear where the overflow occurs.

When child is null, this widget becomes as small as possible and never overflows.

This widget can be used to ensure some of child's natural dimensions are honored, and get an early warning otherwise during development. For instance, if child requires a minimum height to fully display its content, constraintsTransform can be set to maxHeightUnconstrained, so that if the parent RenderObject fails to provide enough vertical space, a warning will be displayed in debug mode, while still allowing child to grow vertically:

In the following snippet, the Card is guaranteed to be at least as tall as its "natural" height. Unlike UnconstrainedBox, it will become taller if its "natural" height is smaller than 40 px. If the Container isn't high enough to show the full content of the Card, in debug mode a warning will be given.
link
Container(
  constraints: const BoxConstraints(minHeight: 40, maxHeight: 100),
  alignment: Alignment.center,
  child: const ConstraintsTransformBox(
    constraintsTransform: ConstraintsTransformBox.maxHeightUnconstrained,
    child: Card(child: Text('Hello World!')),
  )
)

See also:

  • ConstrainedBox, which renders a box which imposes constraints on its child.
  • OverflowBox, a widget that imposes additional constraints on its child, and allows the child to overflow itself.
  • UnconstrainedBox which allows its children to render themselves unconstrained and expands to fit them.
Inheritance

Constructors

ConstraintsTransformBox({Key? key, Widget? child, TextDirection? textDirection, AlignmentGeometry alignment = Alignment.center, required BoxConstraintsTransform constraintsTransform, Clip clipBehavior = Clip.none, String debugTransformType = ''})
Creates a widget that uses a function to transform the constraints it passes to its child. If the child overflows the parent's constraints, a warning will be given in debug mode.
const

Properties

alignment AlignmentGeometry
The alignment to use when laying out the child, if it has a different size than this widget.
final
child Widget?
The widget below this widget in the tree.
finalinherited
clipBehavior Clip
The content will be clipped (or not) according to this option.
final
constraintsTransform BoxConstraintsTransform
The function used to transform the incoming BoxConstraints, to size child.
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
textDirection TextDirection?
The text direction to use when interpreting the alignment if it is an AlignmentDirectional.
final

Methods

createElement() SingleChildRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
inherited
createRenderObject(BuildContext context) RenderConstraintsTransformBox
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget.
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.
override
didUnmountRenderObject(covariant RenderObject renderObject) → void
A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object's createRenderObject.
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}) 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
updateRenderObject(BuildContext context, covariant RenderConstraintsTransformBox renderObject) → void
Copies the configuration described by this RenderObjectWidget to the given RenderObject, which will be of the same type as returned by this object's createRenderObject.
override

Operators

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

Static Methods

heightUnconstrained(BoxConstraints constraints) BoxConstraints
A BoxConstraintsTransform that removes the height constraints from the input.
maxHeightUnconstrained(BoxConstraints constraints) BoxConstraints
A BoxConstraintsTransform that removes the maxHeight constraint from the input.
maxUnconstrained(BoxConstraints constraints) BoxConstraints
A BoxConstraintsTransform that removes both the maxWidth and the maxHeight constraints from the input.
maxWidthUnconstrained(BoxConstraints constraints) BoxConstraints
A BoxConstraintsTransform that removes the maxWidth constraint from the input.
unconstrained(BoxConstraints constraints) BoxConstraints
A BoxConstraintsTransform that always returns a BoxConstraints that imposes no constraints on either dimension (i.e. const BoxConstraints()).
unmodified(BoxConstraints constraints) BoxConstraints
A BoxConstraintsTransform that always returns its argument as-is (i.e., it is an identity function).
widthUnconstrained(BoxConstraints constraints) BoxConstraints
A BoxConstraintsTransform that removes the width constraints from the input.