Unverified Commit 003608f1 authored by hangyu's avatar hangyu Committed by GitHub

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
parent e52449b6
......@@ -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)!;
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment