Skip to content

Commit

Permalink
Label should always be aligned with text in filled input decoration (…
Browse files Browse the repository at this point in the history
…#115540)

Co-authored-by: Qun Cheng <[email protected]>
  • Loading branch information
QuncCccccc and QuncCccccc authored Nov 17, 2022
1 parent 31f8631 commit a1ea383
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/material/input_decorator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1555,14 +1555,14 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
case TextDirection.rtl: // origin is on the right
startX = labelOffset.dx + labelWidth * (1.0 - scale);
floatStartX = startX;
if (prefixIcon != null && !decoration.alignLabelWithHint) {
if (prefixIcon != null && !decoration.alignLabelWithHint && isOutlineBorder) {
floatStartX += material3 ? _boxSize(prefixIcon).width - contentPadding.left : 0.0;
}
break;
case TextDirection.ltr: // origin on the left
startX = labelOffset.dx;
floatStartX = startX;
if (prefixIcon != null && !decoration.alignLabelWithHint) {
if (prefixIcon != null && !decoration.alignLabelWithHint && isOutlineBorder) {
floatStartX += material3 ? -_boxSize(prefixIcon).width + contentPadding.left : 0.0;
}
break;
Expand Down
19 changes: 19 additions & 0 deletions packages/flutter/test/material/input_decorator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,25 @@ void main() {
expect(tester.getBottomLeft(find.text('text')).dx, 48.0);
expect(getBorderWeight(tester), 2.0);
});

testWidgets('Floating label for filled input decoration is aligned with text', (WidgetTester tester) async {
await tester.pumpWidget(
buildInputDecorator(
useMaterial3: useMaterial3,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.ac_unit),
labelText: 'label',
filled: true,
),
isFocused: true,
),
);

expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
expect(tester.getTopLeft(find.text('label')).dx, 48.0);
expect(tester.getBottomLeft(find.text('text')).dx, 48.0);
expect(getBorderWeight(tester), 2.0);
});
});

group('3 point interpolation alignment', () {
Expand Down

0 comments on commit a1ea383

Please sign in to comment.