mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Added BorderRadius.copyWith (#75340)
This commit is contained in:
parent
3f163d29a4
commit
fef72c187d
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user