Skip to content

Commit 5995661

Browse files
authored
Fix outline button solid path when BorderSize.width is used (flutter#51581)
1 parent a732652 commit 5995661

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

packages/flutter/lib/src/material/outline_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ class _OutlineBorder extends ShapeBorder implements MaterialStateProperty<ShapeB
561561
case BorderStyle.none:
562562
break;
563563
case BorderStyle.solid:
564-
canvas.drawPath(shape.getOuterPath(rect, textDirection: textDirection), side.toPaint());
564+
canvas.drawPath(shape.getOuterPath(rect.deflate(side.width / 2.0), textDirection: textDirection), side.toPaint());
565565
}
566566
}
567567

packages/flutter/test/material/outline_button_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,39 @@ void main() {
867867
);
868868
});
869869

870+
testWidgets('OutlineButton uses borderSide width to paint', (WidgetTester tester) async {
871+
final GlobalKey buttonKey = GlobalKey();
872+
const double thickness = 12.5;
873+
await tester.pumpWidget(
874+
Directionality(
875+
textDirection: TextDirection.ltr,
876+
child: Material(
877+
child: Align(
878+
alignment: Alignment.topLeft,
879+
child: OutlineButton(
880+
key: buttonKey,
881+
borderSide: const BorderSide(
882+
color: Colors.black12,
883+
width: thickness),
884+
onPressed: () {},
885+
child: const SizedBox(
886+
width: 120,
887+
height: 50,
888+
child: Text('ABC'),
889+
),
890+
),
891+
),
892+
),
893+
),
894+
);
895+
896+
final Finder outlineButton = find.byType(OutlineButton);
897+
expect(outlineButton, paints..path(
898+
includes: const <Offset>[Offset(60, thickness / 2.0)],
899+
excludes: const <Offset>[Offset(60, thickness / 3.0)],
900+
));
901+
});
902+
870903
testWidgets('OutlineButton contributes semantics', (WidgetTester tester) async {
871904
final SemanticsTester semantics = SemanticsTester(tester);
872905
await tester.pumpWidget(

packages/flutter/test/rendering/mock_canvas.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,13 +1163,15 @@ class _PathPaintPredicate extends _DrawCommandPaintPredicate {
11631163
if (includes != null) {
11641164
for (final Offset offset in includes) {
11651165
if (!pathArgument.contains(offset))
1166-
throw 'It called $methodName with a path that unexpectedly did not contain $offset.';
1166+
throw 'It called $methodName with a path that unexpectedly did not '
1167+
'contain $offset. Path bounds = ${pathArgument.getBounds()}';
11671168
}
11681169
}
11691170
if (excludes != null) {
11701171
for (final Offset offset in excludes) {
11711172
if (pathArgument.contains(offset))
1172-
throw 'It called $methodName with a path that unexpectedly contained $offset.';
1173+
throw 'It called $methodName with a path that unexpectedly '
1174+
'contained $offset. . Path bounds = ${pathArgument.getBounds()}';
11731175
}
11741176
}
11751177
}

0 commit comments

Comments
 (0)