Unverified Commit 0b8403b6 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Add `const Border.uniform()` (#30640)

`Border.all()` is a factory constructor and thus not const
constructible. This change adds a `const Border.uniform()`
constructor and makes `Border.all()` delegate to it. This allows
callers to more likely be able to make their widget tree const
constructible.
parent 949023b2
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment