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
This commit is contained in:
parent
e52449b641
commit
003608f182
@ -978,12 +978,12 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
|
|||||||
0.0,
|
0.0,
|
||||||
constraints.maxWidth - (
|
constraints.maxWidth - (
|
||||||
_boxSize(icon).width
|
_boxSize(icon).width
|
||||||
+ contentPadding.left
|
+ (prefixIcon != null ? 0 : (textDirection == TextDirection.ltr ? contentPadding.left : contentPadding.right))
|
||||||
+ _boxSize(prefixIcon).width
|
+ _boxSize(prefixIcon).width
|
||||||
+ _boxSize(prefix).width
|
+ _boxSize(prefix).width
|
||||||
+ _boxSize(suffix).width
|
+ _boxSize(suffix).width
|
||||||
+ _boxSize(suffixIcon).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.
|
// Increase the available width for the label when it is scaled down.
|
||||||
final double invertedLabelScale = lerpDouble(1.00, 1 / _kFinalLabelScale, decoration.floatingLabelProgress)!;
|
final double invertedLabelScale = lerpDouble(1.00, 1 / _kFinalLabelScale, decoration.floatingLabelProgress)!;
|
||||||
|
@ -3182,6 +3182,65 @@ void main() {
|
|||||||
expect(FloatingLabelAlignment.center.toString(), 'FloatingLabelAlignment.center');
|
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', () {
|
group('floatingLabelAlignment', () {
|
||||||
Widget buildInputDecoratorWithFloatingLabel({required TextDirection textDirection,
|
Widget buildInputDecoratorWithFloatingLabel({required TextDirection textDirection,
|
||||||
required bool hasIcon,
|
required bool hasIcon,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user