diff --git a/packages/flutter/lib/src/material/input_border.dart b/packages/flutter/lib/src/material/input_border.dart index b9d4d8e1e7..af6508f232 100644 --- a/packages/flutter/lib/src/material/input_border.dart +++ b/packages/flutter/lib/src/material/input_border.dart @@ -476,14 +476,14 @@ class OutlineInputBorder extends InputBorder { // Draw top border from top left corner to gap start. if (start > scaledRRect.tlRadiusX) { - path.lineTo(scaledRRect.left + start, scaledRRect.top); + path.lineTo(start, scaledRRect.top); } // Draw top border from gap end to top right corner and draw top right corner. const double trCornerArcStart = (3 * math.pi) / 2.0; const double trCornerArcSweep = cornerArcSweep; if (start + extent < outerWidth - scaledRRect.trRadiusX) { - path.moveTo(scaledRRect.left + start + extent, scaledRRect.top); + path.moveTo(start + extent, scaledRRect.top); path.lineTo(scaledRRect.right - scaledRRect.trRadiusX, scaledRRect.top); if (scaledRRect.trRadius != Radius.zero) { path.addArc(trCorner, trCornerArcStart, trCornerArcSweep); diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 6088f60b32..33a9d894b7 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -1707,6 +1707,74 @@ void main() { ); }); + // Regression test for https://github.com/flutter/flutter/issues/159942. + testWidgets('OutlineBorder does not overlap with the label at the default radius', (WidgetTester tester) async { + Widget buildFrame(TextDirection textDirection) { + return MaterialApp( + home: Scaffold( + body: Container( + padding: const EdgeInsets.all(16.0), + alignment: Alignment.center, + child: Directionality( + textDirection: textDirection, + child: const RepaintBoundary( + child: InputDecorator( + isFocused: true, + decoration: InputDecoration( + labelText: labelText, + border: OutlineInputBorder( + gapPadding: 0.0, + ), + ), + ), + ), + ), + ), + ), + ); + } + + await tester.pumpWidget(buildFrame(TextDirection.ltr)); + Rect labelRect = getLabelRect(tester); + RenderBox borderBox = InputDecorator.containerOf(tester.element(findBorderPainter()))!; + expect(findBorderPainter(), paints + ..save() + ..path( + // The points of the label edge should be part of the border. + includes: [ + borderBox.globalToLocal(labelRect.centerLeft), + borderBox.globalToLocal(labelRect.centerRight), + ], + // The points inside the label should not be part of the border. + excludes: [ + borderBox.globalToLocal(labelRect.centerLeft) + const Offset(1, 0), + borderBox.globalToLocal(labelRect.centerRight) + const Offset(-1, 0), + ], + ) + ..restore(), + ); + + await tester.pumpWidget(buildFrame(TextDirection.rtl)); + labelRect = getLabelRect(tester); + borderBox = InputDecorator.containerOf(tester.element(findBorderPainter()))!; + expect(findBorderPainter(), paints + ..save() + ..path( + // The points of the label edge should be part of the border. + includes: [ + borderBox.globalToLocal(labelRect.centerLeft), + borderBox.globalToLocal(labelRect.centerRight), + ], + // The points inside the label should not be part of the border. + excludes: [ + borderBox.globalToLocal(labelRect.centerLeft) + const Offset(1, 0), + borderBox.globalToLocal(labelRect.centerRight) + const Offset(-1, 0), + ], + ) + ..restore(), + ); + }); + testWidgets('OutlineBorder does not draw over label when input decorator is focused and has an icon', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/18111. Widget buildFrame(TextDirection textDirection) {