Label should always be aligned with text in filled input decoration (#115540)
Co-authored-by: Qun Cheng <quncheng@google.com>
This commit is contained in:
parent
31f8631627
commit
a1ea383fa5
@ -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;
|
||||
|
@ -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', () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user