Container constructor

Container({Key key, AlignmentGeometry alignment, EdgeInsetsGeometry padding, Color color, Decoration decoration, Decoration foregroundDecoration, double width, double height, BoxConstraints constraints, EdgeInsetsGeometry margin, Matrix4 transform, Widget child })

Creates a widget that combines common painting, positioning, and sizing widgets.

The height and width values include the padding.

The color argument is a shorthand for decoration: new BoxDecoration(color: color), which means you cannot supply both a color and a decoration argument. If you want to have both a color and a decoration, you can pass the color as the color argument to the BoxDecoration.

Implementation

Container({
  Key key,
  this.alignment,
  this.padding,
  Color color,
  Decoration decoration,
  this.foregroundDecoration,
  double width,
  double height,
  BoxConstraints constraints,
  this.margin,
  this.transform,
  this.child,
}) : assert(margin == null || margin.isNonNegative),
     assert(padding == null || padding.isNonNegative),
     assert(decoration == null || decoration.debugAssertIsValid()),
     assert(constraints == null || constraints.debugAssertIsValid()),
     assert(color == null || decoration == null,
       'Cannot provide both a color and a decoration\n'
       'The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".'
     ),
     decoration = decoration ?? (color != null ? BoxDecoration(color: color) : null),
     constraints =
      (width != null || height != null)
        ? constraints?.tighten(width: width, height: height)
          ?? BoxConstraints.tightFor(width: width, height: height)
        : constraints,
     super(key: key);