Unverified Commit fef72c18 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Added BorderRadius.copyWith (#75340)

parent 3f163d29
......@@ -327,6 +327,22 @@ class BorderRadius extends BorderRadiusGeometry {
this.bottomRight = Radius.zero,
});
/// Returns a copy of this BorderRadius with the given fields replaced with
/// the new values.
BorderRadius copyWith({
Radius? topLeft,
Radius? topRight,
Radius? bottomLeft,
Radius? bottomRight,
}) {
return BorderRadius.only(
topLeft: topLeft ?? this.topLeft,
topRight: topRight ?? this.topRight,
bottomLeft: bottomLeft ?? this.bottomLeft,
bottomRight: bottomRight ?? this.bottomRight,
);
}
/// A border radius with all zero radii.
static const BorderRadius zero = BorderRadius.all(Radius.zero);
......
......@@ -536,4 +536,24 @@ void main() {
expect((a.add(b.subtract(a) * 0.0)).resolve(TextDirection.ltr), a);
expect((a.add(b.subtract(a) * 1.0)).resolve(TextDirection.rtl), b.resolve(TextDirection.rtl));
});
test('BorderRadius copyWith, merge, ==, hashCode basics', () {
const BorderRadius firstRadius = BorderRadius.all(Radius.circular(5.0));
final BorderRadius secondRadius = firstRadius.copyWith();
expect(firstRadius, secondRadius);
expect(firstRadius.hashCode, secondRadius.hashCode);
});
test('BorderRadius copyWith parameters', () {
const Radius radius = Radius.circular(10);
const BorderRadius borderRadius = BorderRadius.all(radius);
expect(borderRadius.copyWith(topLeft: Radius.zero).topLeft, Radius.zero);
expect(borderRadius.copyWith(topLeft: Radius.zero).copyWith(topLeft: radius), borderRadius);
expect(borderRadius.copyWith(topRight: Radius.zero).topRight, Radius.zero);
expect(borderRadius.copyWith(topRight: Radius.zero).copyWith(topRight: radius), borderRadius);
expect(borderRadius.copyWith(bottomLeft: Radius.zero).bottomLeft, Radius.zero);
expect(borderRadius.copyWith(bottomLeft: Radius.zero).copyWith(bottomLeft: radius), borderRadius);
expect(borderRadius.copyWith(bottomRight: Radius.zero).bottomRight, Radius.zero);
expect(borderRadius.copyWith(bottomRight: Radius.zero).copyWith(bottomRight: radius), borderRadius);
});
}
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