An immutable description of how to paint a box.

The BoxDecoration class provides a variety of ways to draw a box.

The box has a border, a body, and may cast a boxShadow.

The shape of the box can be a circle or a rectangle. If it is a rectangle, then the borderRadius property controls the roundness of the corners.

The body of the box is painted in layers. The bottom-most layer is the color, which fills the box. Above that is the gradient, which also fills the box. Finally there is the image, the precise alignment of which is controlled by the DecorationImage class.

The border paints over the body; the boxShadow, naturally, paints below it.

Sample code

The following example uses the Container widget from the widgets layer to draw an image with a border:

new Container(
  decoration: new BoxDecoration(
    color: const Color(0xff7c94b6),
    image: new DecorationImage(
      image: new ExactAssetImage('images/flowers.jpeg'),
      fit: BoxFit.cover,
    ),
    border: new Border.all(
      color: Colors.black,
      width: 8.0,
    ),
  ),
)

See also:

Inheritance

Constructors

BoxDecoration({Color color, DecorationImage image, Border border, BorderRadius borderRadius, List<BoxShadow> boxShadow, Gradient gradient, BoxShape shape: BoxShape.rectangle })
Creates a box decoration. [...]
const

Properties

border Border
A border to draw above the background color or image.
final
borderRadius BorderRadius
If non-null, the corners of this box are rounded by this BorderRadius. [...]
final
boxShadow List<BoxShadow>
A list of shadows cast by this box behind the box. [...]
final
color Color
The color to fill in the background of the box. [...]
final
gradient Gradient
A gradient to use when filling the box.
final
hashCode int
@override, read-only
image DecorationImage
An image to paint above the background color. If shape is BoxShape.circle then the image is clipped to the circle's boundary.
final
isComplex bool
@override, read-only
padding EdgeInsets
The inset space occupied by the border.
@override, read-only
shape BoxShape
The shape to fill the background color into and to cast as the boxShadow.
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

createBoxPainter([VoidCallback onChanged ]) → _BoxDecorationPainter
Returns a BoxPainter that will paint this decoration. [...]
debugAssertIsValid() bool
In checked mode, throws an exception if the object is not in a valid configuration. Otherwise, returns true. [...]
hitTest(Size size, Offset position) bool
Tests whether the given point, on a rectangle of a given size, would be considered to hit the decoration or not. For example, if the decoration only draws a circle, this function might return true if the point was inside the circle and false otherwise.
lerpFrom(Decoration a, double t) BoxDecoration
Linearly interpolates from a to this.
lerpTo(Decoration b, double t) BoxDecoration
Linearly interpolates from this to b.
scale(double factor) BoxDecoration
Returns a new box decoration that is scaled by the given factor.
toString([String prefix = '', String indentPrefix ]) String
Stringifies the BoxDecoration. By default, the output will be on one line. If the method is passed a non-empty string argument, then the output will span multiple lines, each prefixed by that argument.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(other) bool
The equality operator. [...]

Static Methods

lerp(BoxDecoration a, BoxDecoration b, double t) BoxDecoration
Linearly interpolate between two box decorations. [...]