Added BorderRadius.copyWith (#75340)

This commit is contained in:
Hans Muller 2021-02-03 11:02:00 -08:00 committed by GitHub
parent 3f163d29a4
commit fef72c187d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -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);

View File

@ -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);
});
}