Skip to content

Commit a1ea383

Browse files
authored
Label should always be aligned with text in filled input decoration (#115540)
Co-authored-by: Qun Cheng <[email protected]>
1 parent 31f8631 commit a1ea383

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,14 +1555,14 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
15551555
case TextDirection.rtl: // origin is on the right
15561556
startX = labelOffset.dx + labelWidth * (1.0 - scale);
15571557
floatStartX = startX;
1558-
if (prefixIcon != null && !decoration.alignLabelWithHint) {
1558+
if (prefixIcon != null && !decoration.alignLabelWithHint && isOutlineBorder) {
15591559
floatStartX += material3 ? _boxSize(prefixIcon).width - contentPadding.left : 0.0;
15601560
}
15611561
break;
15621562
case TextDirection.ltr: // origin on the left
15631563
startX = labelOffset.dx;
15641564
floatStartX = startX;
1565-
if (prefixIcon != null && !decoration.alignLabelWithHint) {
1565+
if (prefixIcon != null && !decoration.alignLabelWithHint && isOutlineBorder) {
15661566
floatStartX += material3 ? -_boxSize(prefixIcon).width + contentPadding.left : 0.0;
15671567
}
15681568
break;

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,25 @@ void main() {
28422842
expect(tester.getBottomLeft(find.text('text')).dx, 48.0);
28432843
expect(getBorderWeight(tester), 2.0);
28442844
});
2845+
2846+
testWidgets('Floating label for filled input decoration is aligned with text', (WidgetTester tester) async {
2847+
await tester.pumpWidget(
2848+
buildInputDecorator(
2849+
useMaterial3: useMaterial3,
2850+
decoration: const InputDecoration(
2851+
prefixIcon: Icon(Icons.ac_unit),
2852+
labelText: 'label',
2853+
filled: true,
2854+
),
2855+
isFocused: true,
2856+
),
2857+
);
2858+
2859+
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
2860+
expect(tester.getTopLeft(find.text('label')).dx, 48.0);
2861+
expect(tester.getBottomLeft(find.text('text')).dx, 48.0);
2862+
expect(getBorderWeight(tester), 2.0);
2863+
});
28452864
});
28462865

28472866
group('3 point interpolation alignment', () {

0 commit comments

Comments
 (0)