ConstraintsTransformBoxModifier class
A container widget that applies an arbitrary transform to its constraints, and sizes its child using the resulting BoxConstraints, treating any overflow as 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 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:
{@tool snippet} 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.
Container(
constraints: const BoxConstraints(minHeight: 40, maxHeight: 100),
alignment: Alignment.center,
child: const ConstraintsTransformBox(
constraintsTransform: ConstraintsTransformBox.maxHeightUnconstrained,
child: Card(child: Text('Hello World!')),
)
)
{@end-tool}
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, expands to fit them, and considers overflow to be an error.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- SingleChildStatelessModifier
- ConstraintsTransformBoxModifier
- Available extensions
Constructors
- ConstraintsTransformBoxModifier({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
- 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
- modifierKey → Key?
-
The actual key of the widget, which Modifier wrapped
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
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
inherited
-
buildWithChild(
BuildContext context, Widget? child) → Widget -
A build method that receives an extra
child
parameter.override -
createElement(
) → SingleChildStatelessElement -
Create a SingleChildStatelessElement
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
-
modified(
) → Modifier -
Available on Widget, provided by the ModifierTransformer extension
Transform normal widget to Modifier -
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