From 784f19c49c7089f38f55349cea76ce03104ea246 Mon Sep 17 00:00:00 2001 From: Bernardo Ferrari Date: Thu, 21 Mar 2024 23:31:16 -0300 Subject: [PATCH] Fix `BorderSide.none` requiring explicit transparent color for `UnderlineInputBorder` (#145329) Fix could have been "paint transparent when Border none" but, following other Borders, we will just not paint anything. Fix https://github.com/flutter/flutter/issues/143746 --- .../flutter/lib/src/material/input_border.dart | 4 ++++ .../test/material/input_decorator_test.dart | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/flutter/lib/src/material/input_border.dart b/packages/flutter/lib/src/material/input_border.dart index ae9314a08d..a0ddae07d1 100644 --- a/packages/flutter/lib/src/material/input_border.dart +++ b/packages/flutter/lib/src/material/input_border.dart @@ -243,6 +243,10 @@ class UnderlineInputBorder extends InputBorder { double gapPercentage = 0.0, TextDirection? textDirection, }) { + if (borderSide.style == BorderStyle.none) { + return; + } + if (borderRadius.bottomLeft != Radius.zero || borderRadius.bottomRight != Radius.zero) { // This prevents the border from leaking the color due to anti-aliasing rounding errors. final BorderRadius updatedBorderRadius = BorderRadius.only( diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index e098d1ce2b..f907f51983 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -9729,4 +9729,18 @@ void main() { expect(tester.renderObject(find.text('COUNTER')).size, Size.zero); }); }); + + testWidgets('UnderlineInputBorder with BorderStyle.none should not show anything', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/143746 + const InputDecoration decoration = InputDecoration( + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide(style: BorderStyle.none), + borderRadius: BorderRadius.all(Radius.circular(4)), + ), + ); + + await tester.pumpWidget(buildInputDecorator(decoration: decoration)); + final RenderBox box = tester.renderObject(find.byType(InputDecorator)); + expect(box, isNot(paints..drrect())); + }); }