Container class

Type of container

A convenience widget that combines common painting, positioning, and sizing widgets.

A convenient component (widget) that combines rendering, positioning, sizing, etc.

A container first surrounds the child with padding (inflated by any borders present in the decoration) and then applies additional constraints to the padded extent (incorporating the width and height as constraints, if either is non-null). The container is then surrounded by additional empty space described from the margin.

This container has the usual padding, margin, width, height attributes.

During painting, the container first applies the given transform, then paints the decoration to fill the padded extent, then it paints the child, and finally paints the foregroundDecoration, also filling the padded extent.

During rendering, the Container applies the Transform property, then renders some decorative properties to fill the content, and then renders the Child, along with some messy decorative properties.

Containers with no children try to be as big as possible unless the incoming constraints are unbounded, in which case they try to be as small as possible. Containers with children size themselves to their children. The width, height, and constraints arguments to the constructor override this.

If there are no elements in the Container, the size of the container will fill the screen unless it is limited by width and height. If there are child elements, the container will adapt to the size of the child, and you can adjust some of the other padding and margin attributes to render the way you want. That’s not what the literal translation means

By default, containers return false for all hit tests. If the color property is specified, the hit testing is handled by ColoredBox, which always returns true. If the decoration or foregroundDecoration properties are specified, hit testing is handled by Decoration.hitTest.

By default, container returns false during hit test. For example, if the color attribute is set, the hit test is handled by the ColorBox, which always returns true. Whenever you set a property, there will be a handler.

The official example

Container(margin: const EdgeInsets. All (10.0), color: color.amber [600], width: 48.0, height: 48.0,),Copy the code

This is a 48-by-48 square with a yellow background.

Container( constraints: BoxConstraints.expand( height: Theme.of(context).textTheme.headline4! .fontSize! * 1.1 + 200.0,), paddING-color: const EdgeInsets. All (8.0), color: color.blue [600], alignment: align.center, child: Text('Hello World', style: Theme.of(context) .textTheme .headline4! .copywith (color: color.white)), transform: matrix4.rotationz (0.1),)Copy the code

This sample code, there is a problem, compilation will report an error, the problem appears in! An exclamation point.

Looks like 2.0 was born, this thing changed? After I remove it, I render the example perfectly

Touch fish so far, slip slip, white…