diff --git a/packages/flutter/lib/src/painting/box_border.dart b/packages/flutter/lib/src/painting/box_border.dart index e367d7af2b..375013b4f7 100644 --- a/packages/flutter/lib/src/painting/box_border.dart +++ b/packages/flutter/lib/src/painting/box_border.dart @@ -314,6 +314,16 @@ class Border extends BoxBorder { assert(bottom != null), assert(left != null); + /// Creates a border whose sides are all the same. + /// + /// The `side` argument must not be null. + const Border.uniform(BorderSide side) + : assert(side != null), + top = side, + right = side, + bottom = side, + left = side; + /// A uniform border with all sides the same color and width. /// /// The sides default to black solid borders, one logical pixel wide. @@ -323,7 +333,7 @@ class Border extends BoxBorder { BorderStyle style = BorderStyle.solid, }) { final BorderSide side = BorderSide(color: color, width: width, style: style); - return Border(top: side, right: side, bottom: side, left: side); + return Border.uniform(side); } /// Creates a [Border] that represents the addition of the two given diff --git a/packages/flutter/test/painting/border_test.dart b/packages/flutter/test/painting/border_test.dart index 6cc94bf688..7e7a42e99b 100644 --- a/packages/flutter/test/painting/border_test.dart +++ b/packages/flutter/test/painting/border_test.dart @@ -13,6 +13,16 @@ void main() { expect(() => Border(bottom: nonconst(null)), throwsAssertionError); }); + test('Border.uniform constructor', () { + expect(() => Border.uniform(null), throwsAssertionError); + const BorderSide side = BorderSide(); + const Border border = Border.uniform(side); + expect(border.left, same(side)); + expect(border.top, same(side)); + expect(border.right, same(side)); + expect(border.bottom, same(side)); + }); + test('Border.merge', () { const BorderSide magenta3 = BorderSide(color: Color(0xFFFF00FF), width: 3.0); const BorderSide magenta6 = BorderSide(color: Color(0xFFFF00FF), width: 6.0);