Unverified Commit 804a7b28 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Make `CupertinoTextField` at least as tall as its first line of placeholder (#134198)

Fixes https://github.com/flutter/flutter/issues/133241
and some CupertinoTextField cleanup.
parent fc671188
...@@ -444,7 +444,7 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField> ...@@ -444,7 +444,7 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
suffix: suffix, suffix: suffix,
keyboardType: widget.keyboardType, keyboardType: widget.keyboardType,
onTap: widget.onTap, onTap: widget.onTap,
enabled: widget.enabled, enabled: widget.enabled ?? true,
suffixMode: widget.suffixMode, suffixMode: widget.suffixMode,
placeholder: placeholder, placeholder: placeholder,
placeholderStyle: placeholderStyle, placeholderStyle: placeholderStyle,
......
...@@ -219,7 +219,7 @@ class CupertinoTextFormFieldRow extends FormField<String> { ...@@ -219,7 +219,7 @@ class CupertinoTextFormFieldRow extends FormField<String> {
onEditingComplete: onEditingComplete, onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted, onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters, inputFormatters: inputFormatters,
enabled: enabled, enabled: enabled ?? true,
cursorWidth: cursorWidth, cursorWidth: cursorWidth,
cursorHeight: cursorHeight, cursorHeight: cursorHeight,
cursorColor: cursorColor, cursorColor: cursorColor,
......
...@@ -569,15 +569,11 @@ class RenderStack extends RenderBox ...@@ -569,15 +569,11 @@ class RenderStack extends RenderBox
double width = constraints.minWidth; double width = constraints.minWidth;
double height = constraints.minHeight; double height = constraints.minHeight;
final BoxConstraints nonPositionedConstraints; final BoxConstraints nonPositionedConstraints = switch (fit) {
switch (fit) { StackFit.loose => constraints.loosen(),
case StackFit.loose: StackFit.expand => BoxConstraints.tight(constraints.biggest),
nonPositionedConstraints = constraints.loosen(); StackFit.passthrough => constraints,
case StackFit.expand: };
nonPositionedConstraints = BoxConstraints.tight(constraints.biggest);
case StackFit.passthrough:
nonPositionedConstraints = constraints;
}
RenderBox? child = firstChild; RenderBox? child = firstChild;
while (child != null) { while (child != null) {
......
...@@ -1071,7 +1071,8 @@ void main() { ...@@ -1071,7 +1071,8 @@ void main() {
await tester.enterText(find.byType(CupertinoTextField), 'input'); await tester.enterText(find.byType(CupertinoTextField), 'input');
await tester.pump(); await tester.pump();
expect(find.text('placeholder'), findsNothing); final Element element = tester.element(find.text('placeholder'));
expect(Visibility.of(element), false);
}, },
); );
...@@ -1964,7 +1965,9 @@ void main() { ...@@ -1964,7 +1965,9 @@ void main() {
expect(find.text('field 1'), findsOneWidget); expect(find.text('field 1'), findsOneWidget);
expect(find.text("j'aime la poutine"), findsOneWidget); expect(find.text("j'aime la poutine"), findsOneWidget);
expect(find.text('field 2'), findsNothing);
final Element placeholder2Element = tester.element(find.text('field 2'));
expect(Visibility.of(placeholder2Element), false);
}, skip: isContextMenuProvidedByPlatform); // [intended] only applies to platforms where we supply the context menu. }, skip: isContextMenuProvidedByPlatform); // [intended] only applies to platforms where we supply the context menu.
testWidgets( testWidgets(
...@@ -8096,9 +8099,7 @@ void main() { ...@@ -8096,9 +8099,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const CupertinoApp( const CupertinoApp(
home: Center( home: Center(
child: CupertinoTextField( child: CupertinoTextField(),
enabled: true,
),
), ),
), ),
); );
...@@ -9867,4 +9868,59 @@ void main() { ...@@ -9867,4 +9868,59 @@ void main() {
skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu. skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu.
variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS }), variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS }),
); );
testWidgets('Does not shrink in height when enters text when there is large single-line placeholder', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/133241.
final TextEditingController controller = TextEditingController();
await tester.pumpWidget(
CupertinoApp(
home: Align(
alignment: Alignment.topCenter,
child: CupertinoTextField(
placeholderStyle: const TextStyle(fontSize: 100),
placeholder: 'p',
controller: controller,
),
),
),
);
final Rect rectWithPlaceholder = tester.getRect(find.byType(CupertinoTextField));
controller.value = const TextEditingValue(text: 'input');
await tester.pump();
final Rect rectWithText = tester.getRect(find.byType(CupertinoTextField));
expect(rectWithPlaceholder, rectWithText);
});
testWidgets('Does not match the height of a multiline placeholder', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController();
await tester.pumpWidget(
CupertinoApp(
home: Align(
alignment: Alignment.topCenter,
child: CupertinoTextField(
placeholderStyle: const TextStyle(fontSize: 100),
placeholder: 'p' * 50,
maxLines: null,
controller: controller,
),
),
),
);
final Rect rectWithPlaceholder = tester.getRect(find.byType(CupertinoTextField));
controller.value = const TextEditingValue(text: 'input');
await tester.pump();
final Rect rectWithText = tester.getRect(find.byType(CupertinoTextField));
// The text field is still top aligned.
expect(rectWithPlaceholder.top, rectWithText.top);
// But after entering text the text field should shrink since the
// placeholder text is huge and multiline.
expect(rectWithPlaceholder.height, greaterThan(rectWithText.height));
// But still should be taller than or the same height of the first line of
// placeholder.
expect(rectWithText.height, greaterThan(100));
});
} }
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