Skip to content

Commit

Permalink
Update text field input width when there are prefix/suffix icons (#11…
Browse files Browse the repository at this point in the history
…6690)

* 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
  • Loading branch information
hannah-hyj authored Dec 8, 2022
1 parent e52449b commit 003608f
Show file tree
Hide file tree
Showing 2 changed files with 61 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 @@ -978,12 +978,12 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
0.0,
constraints.maxWidth - (
_boxSize(icon).width
+ contentPadding.left
+ (prefixIcon != null ? 0 : (textDirection == TextDirection.ltr ? contentPadding.left : contentPadding.right))
+ _boxSize(prefixIcon).width
+ _boxSize(prefix).width
+ _boxSize(suffix).width
+ _boxSize(suffixIcon).width
+ contentPadding.right),
+ (suffixIcon != null ? 0 : (textDirection == TextDirection.ltr ? contentPadding.right : contentPadding.left))),
);
// Increase the available width for the label when it is scaled down.
final double invertedLabelScale = lerpDouble(1.00, 1 / _kFinalLabelScale, decoration.floatingLabelProgress)!;
Expand Down
59 changes: 59 additions & 0 deletions packages/flutter/test/material/input_decorator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3182,6 +3182,65 @@ void main() {
expect(FloatingLabelAlignment.center.toString(), 'FloatingLabelAlignment.center');
});

group('inputText width', () {
testWidgets('outline textField', (WidgetTester tester) async {
await tester.pumpWidget(
buildInputDecorator(
useMaterial3: useMaterial3,
decoration: const InputDecoration(
border: OutlineInputBorder(),
),
),
);
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
expect(tester.getTopLeft(find.text('text')).dx, 12.0);
expect(tester.getTopRight(find.text('text')).dx, 788.0);
});
testWidgets('outline textField with prefix and suffix icons', (WidgetTester tester) async {
await tester.pumpWidget(
buildInputDecorator(
useMaterial3: useMaterial3,
decoration: const InputDecoration(
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.visibility),
suffixIcon: Icon(Icons.close),
),
),
);
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
expect(tester.getTopLeft(find.text('text')).dx, 48.0);
expect(tester.getTopRight(find.text('text')).dx, 752.0);
});
testWidgets('filled textField', (WidgetTester tester) async {
await tester.pumpWidget(
buildInputDecorator(
useMaterial3: useMaterial3,
decoration: const InputDecoration(
filled: true,
),
),
);
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 48.0));
expect(tester.getTopLeft(find.text('text')).dx, 12.0);
expect(tester.getTopRight(find.text('text')).dx, 788.0);
});
testWidgets('filled textField with prefix and suffix icons', (WidgetTester tester) async {
await tester.pumpWidget(
buildInputDecorator(
useMaterial3: useMaterial3,
decoration: const InputDecoration(
filled: true,
prefixIcon: Icon(Icons.visibility),
suffixIcon: Icon(Icons.close),
),
),
);
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 48.0));
expect(tester.getTopLeft(find.text('text')).dx, 48.0);
expect(tester.getTopRight(find.text('text')).dx, 752.0);
});
});

group('floatingLabelAlignment', () {
Widget buildInputDecoratorWithFloatingLabel({required TextDirection textDirection,
required bool hasIcon,
Expand Down

0 comments on commit 003608f

Please sign in to comment.