Skip to content

Commit 003608f

Browse files
authored
Update text field input width when there are prefix/suffix icons (#116690)
* Update input_decorator_test.dart Update input_decorator.dart Update input_decorator.dart Update input_decorator.dart Update input_decorator.dart Update input_decorator.dart Revert "Update input_decorator.dart" This reverts commit 6a6d2fd0c145c15440405060190ef714b78441c9. Update input_decorator.dart Update input_decorator_test.dart Update input_decorator.dart lint * Update input_decorator.dart
1 parent e52449b commit 003608f

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -978,12 +978,12 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
978978
0.0,
979979
constraints.maxWidth - (
980980
_boxSize(icon).width
981-
+ contentPadding.left
981+
+ (prefixIcon != null ? 0 : (textDirection == TextDirection.ltr ? contentPadding.left : contentPadding.right))
982982
+ _boxSize(prefixIcon).width
983983
+ _boxSize(prefix).width
984984
+ _boxSize(suffix).width
985985
+ _boxSize(suffixIcon).width
986-
+ contentPadding.right),
986+
+ (suffixIcon != null ? 0 : (textDirection == TextDirection.ltr ? contentPadding.right : contentPadding.left))),
987987
);
988988
// Increase the available width for the label when it is scaled down.
989989
final double invertedLabelScale = lerpDouble(1.00, 1 / _kFinalLabelScale, decoration.floatingLabelProgress)!;

packages/flutter/test/material/input_decorator_test.dart

+59
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,65 @@ void main() {
31823182
expect(FloatingLabelAlignment.center.toString(), 'FloatingLabelAlignment.center');
31833183
});
31843184

3185+
group('inputText width', () {
3186+
testWidgets('outline textField', (WidgetTester tester) async {
3187+
await tester.pumpWidget(
3188+
buildInputDecorator(
3189+
useMaterial3: useMaterial3,
3190+
decoration: const InputDecoration(
3191+
border: OutlineInputBorder(),
3192+
),
3193+
),
3194+
);
3195+
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
3196+
expect(tester.getTopLeft(find.text('text')).dx, 12.0);
3197+
expect(tester.getTopRight(find.text('text')).dx, 788.0);
3198+
});
3199+
testWidgets('outline textField with prefix and suffix icons', (WidgetTester tester) async {
3200+
await tester.pumpWidget(
3201+
buildInputDecorator(
3202+
useMaterial3: useMaterial3,
3203+
decoration: const InputDecoration(
3204+
border: OutlineInputBorder(),
3205+
prefixIcon: Icon(Icons.visibility),
3206+
suffixIcon: Icon(Icons.close),
3207+
),
3208+
),
3209+
);
3210+
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
3211+
expect(tester.getTopLeft(find.text('text')).dx, 48.0);
3212+
expect(tester.getTopRight(find.text('text')).dx, 752.0);
3213+
});
3214+
testWidgets('filled textField', (WidgetTester tester) async {
3215+
await tester.pumpWidget(
3216+
buildInputDecorator(
3217+
useMaterial3: useMaterial3,
3218+
decoration: const InputDecoration(
3219+
filled: true,
3220+
),
3221+
),
3222+
);
3223+
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 48.0));
3224+
expect(tester.getTopLeft(find.text('text')).dx, 12.0);
3225+
expect(tester.getTopRight(find.text('text')).dx, 788.0);
3226+
});
3227+
testWidgets('filled textField with prefix and suffix icons', (WidgetTester tester) async {
3228+
await tester.pumpWidget(
3229+
buildInputDecorator(
3230+
useMaterial3: useMaterial3,
3231+
decoration: const InputDecoration(
3232+
filled: true,
3233+
prefixIcon: Icon(Icons.visibility),
3234+
suffixIcon: Icon(Icons.close),
3235+
),
3236+
),
3237+
);
3238+
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 48.0));
3239+
expect(tester.getTopLeft(find.text('text')).dx, 48.0);
3240+
expect(tester.getTopRight(find.text('text')).dx, 752.0);
3241+
});
3242+
});
3243+
31853244
group('floatingLabelAlignment', () {
31863245
Widget buildInputDecoratorWithFloatingLabel({required TextDirection textDirection,
31873246
required bool hasIcon,

0 commit comments

Comments
 (0)