Border class

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

The sides are represented by BorderSide objects.

All four borders the same, two-pixel wide solid white:
link
Border.all(width: 2.0, color: const Color(0xFFFFFFFF))

The border for a Material Design divider:
link
Border(bottom: BorderSide(color: Theme.of(context).dividerColor))

A 1990s-era "OK" button:
link
Container(
  decoration: const BoxDecoration(
    border: Border(
      top: BorderSide(color: Color(0xFFFFFFFF)),
      left: BorderSide(color: Color(0xFFFFFFFF)),
      right: BorderSide(),
      bottom: BorderSide(),
    ),
  ),
  child: Container(
    padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 2.0),
    decoration: const BoxDecoration(
      border: Border(
        top: BorderSide(color: Color(0xFFDFDFDF)),
        left: BorderSide(color: Color(0xFFDFDFDF)),
        right: BorderSide(color: Color(0xFF7F7F7F)),
        bottom: BorderSide(color: Color(0xFF7F7F7F)),
      ),
      color: Color(0xFFBFBFBF),
    ),
    child: const Text(
      'OK',
      textAlign: TextAlign.center,
      style: TextStyle(color: 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 MaterialApp, as shown in the "divider" sample above.
  • paint, which explains the behavior of BoxDecoration parameters.
  • pub.dev/packages/non_uniform_border, a package that implements a Non-Uniform Border on ShapeBorder, which is used by Material Design buttons and other widgets, under the "shape" field.
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, double strokeAlign = BorderSide.strokeAlignInside})
A uniform border with all sides the same color and width.
factory
Border.fromBorderSide(BorderSide side)
Creates a border whose sides are all the same.
const
Border.symmetric({BorderSide vertical = BorderSide.none, BorderSide horizontal = BorderSide.none})
Creates a border with symmetrical vertical and horizontal sides.
const

Properties

bottom BorderSide
The bottom side of this border.
final
dimensions EdgeInsetsGeometry
The widths of the sides of this border represented as an EdgeInsets.
no setteroverride
hashCode int
The hash code for this object.
no setteroverride
isUniform bool
Whether all four sides of the border are identical. Uniform borders are typically more efficient to paint.
no setteroverride
left BorderSide
The left side of this border.
final
preferPaintInterior bool
Reports whether paintInterior is implemented.
no setterinherited
The right side of this border.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
top BorderSide
The top side of this border.
final

Methods

add(ShapeBorder other, {bool reversed = false}) Border?
Attempts to create a new object that represents the amalgamation of this border and the other border.
override
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
lerpFrom(ShapeBorder? a, double t) ShapeBorder?
Linearly interpolates from another ShapeBorder (possibly of another class) to this.
override
lerpTo(ShapeBorder? b, double t) ShapeBorder?
Linearly interpolates from this to another ShapeBorder (possibly of another class).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
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.
override
paintInterior(Canvas canvas, Rect rect, Paint paint, {TextDirection? textDirection}) → void
Paint a canvas with the appropriate shape.
inherited
scale(double t) Border
Creates a copy of this border, scaled by the factor t.
override
toString() String
A string representation of this object.
override

Operators

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

Static Methods

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