Skip to content

Commit

Permalink
borderRadius param updated in copyWith functions (#85822)
Browse files Browse the repository at this point in the history
  • Loading branch information
payam-zahedi committed Jul 12, 2021
1 parent 7a0b466 commit b1e1dd6
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
Expand Up @@ -82,7 +82,7 @@ class BeveledRectangleBorder extends OutlinedBorder {
/// Returns a copy of this RoundedRectangleBorder with the given fields
/// replaced with the new values.
@override
BeveledRectangleBorder copyWith({ BorderSide? side, BorderRadius? borderRadius }) {
BeveledRectangleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius }) {
return BeveledRectangleBorder(
side: side ?? this.side,
borderRadius: borderRadius ?? this.borderRadius,
Expand Down
Expand Up @@ -134,7 +134,7 @@ class ContinuousRectangleBorder extends OutlinedBorder {
}

@override
ContinuousRectangleBorder copyWith({ BorderSide? side, BorderRadius? borderRadius }) {
ContinuousRectangleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius }) {
return ContinuousRectangleBorder(
side: side ?? this.side,
borderRadius: borderRadius ?? this.borderRadius,
Expand Down
Expand Up @@ -93,7 +93,7 @@ class RoundedRectangleBorder extends OutlinedBorder {
/// Returns a copy of this RoundedRectangleBorder with the given fields
/// replaced with the new values.
@override
RoundedRectangleBorder copyWith({ BorderSide? side, BorderRadius? borderRadius }) {
RoundedRectangleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius }) {
return RoundedRectangleBorder(
side: side ?? this.side,
borderRadius: borderRadius ?? this.borderRadius,
Expand Down Expand Up @@ -272,7 +272,7 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
}

@override
_RoundedRectangleToCircleBorder copyWith({ BorderSide? side, BorderRadius? borderRadius, double? circleness }) {
_RoundedRectangleToCircleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius, double? circleness }) {
return _RoundedRectangleToCircleBorder(
side: side ?? this.side,
borderRadius: borderRadius ?? this.borderRadius,
Expand Down
32 changes: 32 additions & 0 deletions packages/flutter/test/painting/beveled_rectangle_border_test.dart
Expand Up @@ -19,10 +19,16 @@ void main() {
expect(const BeveledRectangleBorder().hashCode, const BeveledRectangleBorder().copyWith().hashCode);
const BorderSide side = BorderSide(width: 10.0, color: Color(0xff123456));
const BorderRadius radius = BorderRadius.all(Radius.circular(16.0));
const BorderRadiusDirectional directionalRadius = BorderRadiusDirectional.all(Radius.circular(16.0));
expect(
const BeveledRectangleBorder().copyWith(side: side, borderRadius: radius),
const BeveledRectangleBorder(side: side, borderRadius: radius),
);

expect(
const BeveledRectangleBorder().copyWith(side: side, borderRadius: directionalRadius),
const BeveledRectangleBorder(side: side, borderRadius: directionalRadius),
);
});

test('BeveledRectangleBorder scale and lerp', () {
Expand Down Expand Up @@ -74,4 +80,30 @@ void main() {
expect(border.getInnerPath(rect), looksLikeRect);
});

test('BeveledRectangleBorder non-zero BorderRadiusDirectional', () {
const Rect rect = Rect.fromLTRB(10.0, 20.0, 30.0, 40.0);
final Matcher looksLikeRectLtr = isPathThat(
includes: const <Offset>[Offset(15.0, 25.0), Offset(20.0, 30.0)],
excludes: const <Offset>[Offset(10.0, 20.0), Offset(10.0, 40.0)],
);
const BeveledRectangleBorder border = BeveledRectangleBorder(
borderRadius: BorderRadiusDirectional.only(
topStart: Radius.circular(5.0),
bottomStart: Radius.circular(5.0),
),
);

// Test ltr situation
expect(border.getOuterPath(rect,textDirection: TextDirection.ltr), looksLikeRectLtr);
expect(border.getInnerPath(rect,textDirection: TextDirection.ltr), looksLikeRectLtr);

final Matcher looksLikeRectRtl = isPathThat(
includes: const <Offset>[Offset(25.0, 35.0), Offset(25.0, 25.0)],
excludes: const <Offset>[Offset(30.0, 20.0), Offset(30.0, 40.0)],
);

// Test Rtl situation
expect(border.getOuterPath(rect,textDirection: TextDirection.rtl), looksLikeRectRtl);
expect(border.getInnerPath(rect,textDirection: TextDirection.rtl), looksLikeRectRtl);
});
}
Expand Up @@ -19,10 +19,17 @@ void main() {
expect(const ContinuousRectangleBorder().hashCode, const ContinuousRectangleBorder().copyWith().hashCode);
const BorderSide side = BorderSide(width: 10.0, color: Color(0xff123456));
const BorderRadius radius = BorderRadius.all(Radius.circular(16.0));
const BorderRadiusDirectional directionalRadius = BorderRadiusDirectional.all(Radius.circular(16.0));

expect(
const ContinuousRectangleBorder().copyWith(side: side, borderRadius: radius),
const ContinuousRectangleBorder(side: side, borderRadius: radius),
);

expect(
const ContinuousRectangleBorder().copyWith(side: side, borderRadius: directionalRadius),
const ContinuousRectangleBorder(side: side, borderRadius: directionalRadius),
);
});

test('ContinuousRectangleBorder scale and lerp', () {
Expand Down Expand Up @@ -73,6 +80,31 @@ void main() {
expect(border.getInnerPath(rect), looksLikeRect);
});

test('ContinuousRectangleBorder non-zero BorderRadiusDirectional', () {
const Rect rect = Rect.fromLTRB(10.0, 20.0, 30.0, 40.0);
final Matcher looksLikeRectLtr = isPathThat(
includes: const <Offset>[Offset(15.0, 25.0), Offset(20.0, 30.0)],
excludes: const <Offset>[Offset(10.0, 20.0), Offset(10.0, 40.0)],
);
const ContinuousRectangleBorder border = ContinuousRectangleBorder(
borderRadius: BorderRadiusDirectional.only(
topStart: Radius.circular(5.0),
bottomStart: Radius.circular(5.0),
),
);

expect(border.getOuterPath(rect,textDirection: TextDirection.ltr), looksLikeRectLtr);
expect(border.getInnerPath(rect,textDirection: TextDirection.ltr), looksLikeRectLtr);

final Matcher looksLikeRectRtl = isPathThat(
includes: const <Offset>[Offset(25.0, 35.0), Offset(25.0, 25.0)],
excludes: const <Offset>[Offset(30.0, 20.0), Offset(30.0, 40.0)],
);

expect(border.getOuterPath(rect,textDirection: TextDirection.rtl), looksLikeRectRtl);
expect(border.getInnerPath(rect,textDirection: TextDirection.rtl), looksLikeRectRtl);
});

testWidgets('Golden test even radii', (WidgetTester tester) async {
await tester.pumpWidget(RepaintBoundary(
child: Material(
Expand Down
Expand Up @@ -20,10 +20,17 @@ void main() {
expect(const RoundedRectangleBorder().hashCode, const RoundedRectangleBorder().copyWith().hashCode);
const BorderSide side = BorderSide(width: 10.0, color: Color(0xff123456));
const BorderRadius radius = BorderRadius.all(Radius.circular(16.0));
const BorderRadiusDirectional directionalRadius = BorderRadiusDirectional.all(Radius.circular(16.0));

expect(
const RoundedRectangleBorder().copyWith(side: side, borderRadius: radius),
const RoundedRectangleBorder(side: side, borderRadius: radius),
);

expect(
const RoundedRectangleBorder().copyWith(side: side, borderRadius: directionalRadius),
const RoundedRectangleBorder(side: side, borderRadius: directionalRadius),
);
});

test('RoundedRectangleBorder', () {
Expand Down

0 comments on commit b1e1dd6

Please sign in to comment.