ConstrainedBox class
A widget that imposes additional constraints on its child.
ConstrainedBox 可以为它的子控件强制加上一个约束条件。
For example, if you wanted child to have a minimum height of 50.0 logical pixels, you could use const BoxConstraints(minHeight: 50.0)
as the constraints.
比如你希望子控件拥有最小50像素的高度,你就可以使用
const BoxConstraints(minHeight: 50.0)
Sample
This snippet makes the child widget (a Card with some Text) fill the parent, by applying BoxConstraints.expand constraints:
ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: const Card(child: Text('Hello World!')),
)
The same behavior can be obtained using the new SizedBox.expand widget.
See also:
-
BoxConstraints, the class that describes constraints.
-
UnconstrainedBox, a container that tries to let its child draw without constraints.
-
SizedBox, which lets you specify tight constraints by explicitly specifying the height or width.
-
FractionallySizedBox, which sizes its child based on a fraction of its own size and positions the child according to an Alignment value.
-
AspectRatio, a widget that attempts to fit within the parent’s constraints while also sizing its child to match a given aspect ratio.
-
Inheritance
Object-> Diagnosticable-> DiagnosticableTree-> Widget-> RenderObjectWidget-> SingleChildRenderObjectWidget-> ConstrainedBox