A border of a box, comprised of four sides: top, right, bottom, left.

The sides are represented by BorderSide objects.

Sample code

All four borders the same, two-pixel wide solid white:

new Border.all(width: 2.0, color: const Color(0xFFFFFFFF))

The border for a material design divider:

new Border(bottom: new BorderSide(color: Theme.of(context).dividerColor))

A 1990s-era "OK" button:

new Container(
  decoration: const BoxDecoration(
    border: const Border(
      top: const BorderSide(width: 1.0, color: const Color(0xFFFFFFFFFF)),
      left: const BorderSide(width: 1.0, color: const Color(0xFFFFFFFFFF)),
      right: const BorderSide(width: 1.0, color: const Color(0xFFFF000000)),
      bottom: const BorderSide(width: 1.0, color: const Color(0xFFFF000000)),
    ),
  ),
  child: new Container(
    padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 2.0),
    decoration: const BoxDecoration(
      border: const Border(
        top: const BorderSide(width: 1.0, color: const Color(0xFFFFDFDFDF)),
        left: const BorderSide(width: 1.0, color: const Color(0xFFFFDFDFDF)),
        right: const BorderSide(width: 1.0, color: const Color(0xFFFF7F7F7F)),
        bottom: const BorderSide(width: 1.0, color: const Color(0xFFFF7F7F7F)),
      ),
      color: const Color(0xFFBFBFBF),
    ),
    child: const Text(
      'OK',
      textAlign: TextAlign.center,
      style: const TextStyle(color: const Color(0xFF000000))
    ),
  ),
)

See also:

  • BoxDecoration, which uses this class to describe its edge decoration.
  • BorderSide, which is used to describe each side of the box.
  • Theme, from the material layer, which can be queried to obtain appropriate colors to use for borders in a material app, as shown in the "divider" sample above.
Inheritance

Constructors

Border({BorderSide top: BorderSide.none, BorderSide right: BorderSide.none, BorderSide bottom: BorderSide.none, BorderSide left: BorderSide.none })
Creates a border. [...]
const
Border.all({Color color: const Color(0xFF000000), double width: 1.0, BorderStyle style: BorderStyle.solid })
A uniform border with all sides the same color and width. [...]
factory

Properties

bottom BorderSide
final
dimensions EdgeInsetsGeometry
The widths of the sides of this border represented as an EdgeInsets. [...]
read-only
hashCode int
The hash code for this object. [...]
read-only
isUniform bool
Whether all four sides of the border are identical. Uniform borders are typically more efficient to paint. [...]
read-only
left BorderSide
The left side of this border.
final
The right side of this border.
final
top BorderSide
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

add(ShapeBorder other, { bool reversed: false }) Border
lerpFrom(ShapeBorder a, double t) ShapeBorder
Linearly interpolates from a to this. [...]
lerpTo(ShapeBorder b, double t) ShapeBorder
Linearly interpolates from this to b. [...]
paint(Canvas canvas, Rect rect, { TextDirection textDirection, BoxShape shape: BoxShape.rectangle, BorderRadius borderRadius }) → void
Paints the border within the given Rect on the given Canvas. [...]
scale(double t) Border
Creates a new border with the widths of this border multiplied by t.
toString() String
getInnerPath(Rect rect, { TextDirection textDirection }) Path
Create a Path that describes the inner edge of the border. [...]
inherited
getOuterPath(Rect rect, { TextDirection textDirection }) Path
Create a Path that describes the outer edge of the border. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(other) bool
The equality operator. [...]
operator +(ShapeBorder other) ShapeBorder
Creates a new border consisting of the two borders on either side of the operator. [...]
inherited

Static Methods

lerp(Border a, Border b, double t) Border
Linearly interpolate between two borders. [...]
merge(Border a, Border b) Border
Creates a Border that represents the addition of the two given Borders. [...]