Container constructor
- Key? key,
- AlignmentGeometry? alignment,
- EdgeInsetsGeometry? padding,
- Color? color,
- bool isAntiAlias = true,
- Decoration? decoration,
- Decoration? foregroundDecoration,
- double? width,
- double? height,
- BoxConstraints? constraints,
- EdgeInsetsGeometry? margin,
- Matrix4? transform,
- AlignmentGeometry? transformAlignment,
- Widget? child,
- Clip clipBehavior = Clip.none,
Creates a widget that combines common painting, positioning, and sizing widgets.
The height and width values include the padding.
The color and decoration arguments cannot both be supplied, since
it would potentially result in the decoration drawing over the background
color. To supply a decoration with a color, use decoration: BoxDecoration(color: color).
Implementation
Container({
super.key,
this.alignment,
this.padding,
this.color,
this.isAntiAlias = true,
this.decoration,
this.foregroundDecoration,
double? width,
double? height,
BoxConstraints? constraints,
this.margin,
this.transform,
this.transformAlignment,
this.child,
this.clipBehavior = Clip.none,
}) : assert(margin == null || margin.isNonNegative),
assert(padding == null || padding.isNonNegative),
assert(decoration == null || decoration.debugAssertIsValid()),
assert(constraints == null || constraints.debugAssertIsValid()),
assert(decoration != null || clipBehavior == Clip.none),
assert(
color == null || decoration == null,
'Cannot provide both a color and a decoration.\n'
'The color argument is just a shorthand for "decoration: BoxDecoration(color: color)".\n'
'To use both a color and other decoration properties, set the color in the BoxDecoration instead.',
),
constraints = (width != null || height != null)
? constraints?.tighten(width: width, height: height) ??
BoxConstraints.tightFor(width: width, height: height)
: constraints;