Unverified Commit a12c22b2 authored by xubaolin's avatar xubaolin Committed by GitHub

Set [InputDecoration.floatingLabelBehavior] default to null (#70683)

parent 057e8230
...@@ -2518,7 +2518,7 @@ class InputDecoration { ...@@ -2518,7 +2518,7 @@ class InputDecoration {
'This feature was deprecated after v1.13.2.' 'This feature was deprecated after v1.13.2.'
) )
this.hasFloatingPlaceholder = true, this.hasFloatingPlaceholder = true,
this.floatingLabelBehavior = FloatingLabelBehavior.auto, this.floatingLabelBehavior,
this.isCollapsed = false, this.isCollapsed = false,
this.isDense, this.isDense,
this.contentPadding, this.contentPadding,
...@@ -2564,7 +2564,7 @@ class InputDecoration { ...@@ -2564,7 +2564,7 @@ class InputDecoration {
'This feature was deprecated after v1.13.2.' 'This feature was deprecated after v1.13.2.'
) )
this.hasFloatingPlaceholder = true, this.hasFloatingPlaceholder = true,
this.floatingLabelBehavior = FloatingLabelBehavior.auto, this.floatingLabelBehavior,
this.hintStyle, this.hintStyle,
this.filled = false, this.filled = false,
this.fillColor, this.fillColor,
...@@ -2752,9 +2752,9 @@ class InputDecoration { ...@@ -2752,9 +2752,9 @@ class InputDecoration {
/// ///
/// When [FloatingLabelBehavior.never] the label will always appear in an empty /// When [FloatingLabelBehavior.never] the label will always appear in an empty
/// field in place of the content. /// field in place of the content.
///
/// Defaults to [FloatingLabelBehavior.auto].
/// {@endtemplate} /// {@endtemplate}
///
/// If null, [InputDecorationTheme.floatingLabelBehavior] will be used.
final FloatingLabelBehavior? floatingLabelBehavior; final FloatingLabelBehavior? floatingLabelBehavior;
/// Whether the [InputDecorator.child] is part of a dense form (i.e., uses less vertical /// Whether the [InputDecorator.child] is part of a dense form (i.e., uses less vertical
...@@ -3700,6 +3700,8 @@ class InputDecorationTheme with Diagnosticable { ...@@ -3700,6 +3700,8 @@ class InputDecorationTheme with Diagnosticable {
final bool hasFloatingPlaceholder; final bool hasFloatingPlaceholder;
/// {@macro flutter.material.inputDecoration.floatingLabelBehavior} /// {@macro flutter.material.inputDecoration.floatingLabelBehavior}
///
/// Defaults to [FloatingLabelBehavior.auto].
final FloatingLabelBehavior floatingLabelBehavior; final FloatingLabelBehavior floatingLabelBehavior;
/// Whether the input decorator's child is part of a dense form (i.e., uses /// Whether the input decorator's child is part of a dense form (i.e., uses
......
...@@ -3052,7 +3052,7 @@ void main() { ...@@ -3052,7 +3052,7 @@ void main() {
); );
expect( expect(
child.toString(), child.toString(),
"InputDecorator-[<'key'>](decoration: InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.auto), baseStyle: TextStyle(<all styles inherited>), isFocused: false, isEmpty: false)", "InputDecorator-[<'key'>](decoration: InputDecoration(), baseStyle: TextStyle(<all styles inherited>), isFocused: false, isEmpty: false)",
); );
}); });
......
...@@ -7524,7 +7524,7 @@ void main() { ...@@ -7524,7 +7524,7 @@ void main() {
expect(description, <String>[ expect(description, <String>[
'enabled: false', 'enabled: false',
'decoration: InputDecoration(labelText: "foo", floatingLabelBehavior: FloatingLabelBehavior.auto)', 'decoration: InputDecoration(labelText: "foo")',
'style: TextStyle(inherit: true, color: Color(0xff00ff00))', 'style: TextStyle(inherit: true, color: Color(0xff00ff00))',
'autofocus: true', 'autofocus: true',
'autocorrect: false', 'autocorrect: false',
...@@ -8691,4 +8691,58 @@ void main() { ...@@ -8691,4 +8691,58 @@ void main() {
expect(inputWidth, wideWidth); expect(inputWidth, wideWidth);
expect(cursorRight, inputWidth - kCaretGap); expect(cursorRight, inputWidth - kCaretGap);
}); });
// Regressing test for https://github.com/flutter/flutter/issues/70625
testWidgets('TextFields can inherit [FloatingLabelBehaviour] from InputDecorationTheme.', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
Widget textFieldBuilder({FloatingLabelBehavior behavior = FloatingLabelBehavior.auto, }) {
return MaterialApp(
theme: ThemeData(
inputDecorationTheme: InputDecorationTheme(
floatingLabelBehavior: behavior,
),
),
home: Scaffold(
body: TextField(
focusNode: focusNode,
decoration: const InputDecoration(
labelText: 'Label',
),
),
),
);
}
await tester.pumpWidget(textFieldBuilder(behavior: FloatingLabelBehavior.auto));
// The label will be positioned within the content when unfocused.
expect(tester.getTopLeft(find.text('Label')).dy, 20.0);
focusNode.requestFocus();
await tester.pumpAndSettle(); // label animation.
// The label will float above the content when focused.
expect(tester.getTopLeft(find.text('Label')).dy, 12.0);
focusNode.unfocus();
await tester.pumpAndSettle(); // label animation.
await tester.pumpWidget(textFieldBuilder(behavior: FloatingLabelBehavior.never));
await tester.pumpAndSettle(); // theme animation.
// The label will be positioned within the content.
expect(tester.getTopLeft(find.text('Label')).dy, 20.0);
focusNode.requestFocus();
await tester.pumpAndSettle(); // label animation.
// The label will always be positioned within the content.
expect(tester.getTopLeft(find.text('Label')).dy, 20.0);
await tester.pumpWidget(textFieldBuilder(behavior: FloatingLabelBehavior.always));
await tester.pumpAndSettle(); // theme animation.
// The label will always float above the content.
expect(tester.getTopLeft(find.text('Label')).dy, 12.0);
focusNode.unfocus();
await tester.pumpAndSettle(); // label animation.
// The label will always float above the content.
expect(tester.getTopLeft(find.text('Label')).dy, 12.0);
});
} }
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