Commit 6852605c authored by Josh Burton's avatar Josh Burton Committed by Flutter GitHub Bot

Adds floatLabelBehavior to InputDecoration (#46115)

parent c195b771
......@@ -124,6 +124,7 @@ void main() {
),
),
);
await tester.pumpAndSettle();
// Overall height for this InputDecorator is 56dps:
// 12 - top padding
......@@ -140,6 +141,59 @@ void main() {
expect(getBorderBottom(tester), 56.0);
expect(getBorderWeight(tester), 1.0);
// The label appears within the input when there is no text content
await tester.pumpWidget(
buildInputDecorator(
isEmpty: true,
// isFocused: false (default)
decoration: const InputDecoration(
labelText: 'label',
),
),
);
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
// The label appears above the input text when there is no content and floatingLabelBehavior is always
await tester.pumpWidget(
buildInputDecorator(
isEmpty: true,
// isFocused: false (default)
decoration: const InputDecoration(
labelText: 'label',
floatingLabelBehavior: FloatingLabelBehavior.always
),
),
);
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.text('label')).dy, 12.0);
// The label appears within the input text when there is content and floatingLabelBehavior is never
await tester.pumpWidget(
buildInputDecorator(
isEmpty: false,
// isFocused: false (default)
decoration: const InputDecoration(
labelText: 'label',
floatingLabelBehavior: FloatingLabelBehavior.never
),
),
);
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
// Overall height for this InputDecorator is 56dps:
// 12 - top padding
// 12 - floating label (ahem font size 16dps * 0.75 = 12)
// 4 - floating label / input text gap
// 16 - input text (ahem font size 16dps)
// 12 - bottom padding
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
// isFocused: true increases the border's weight from 1.0 to 2.0
// but does not change the overall height.
await tester.pumpWidget(
......@@ -2476,6 +2530,7 @@ void main() {
isEmpty: true,
decoration: const InputDecoration(
border: OutlineInputBorder(borderSide: BorderSide.none),
// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: false,
labelText: 'label',
),
......@@ -2500,6 +2555,7 @@ void main() {
// isFocused: false (default)
decoration: const InputDecoration(
border: OutlineInputBorder(borderSide: BorderSide.none),
// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: false,
labelText: 'label',
),
......@@ -2679,7 +2735,7 @@ void main() {
);
expect(
child.toString(),
"InputDecorator-[<'key'>](decoration: InputDecoration(), baseStyle: TextStyle(<all styles inherited>), isFocused: false, isEmpty: false)",
"InputDecorator-[<'key'>](decoration: InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.auto), baseStyle: TextStyle(<all styles inherited>), isFocused: false, isEmpty: false)",
);
});
......@@ -3509,7 +3565,9 @@ void main() {
helperMaxLines: 6,
hintStyle: TextStyle(),
errorMaxLines: 5,
// ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: false,
floatingLabelBehavior: FloatingLabelBehavior.never,
contentPadding: EdgeInsetsDirectional.only(start: 40.0, top: 12.0, bottom: 12.0),
prefixStyle: TextStyle(),
suffixStyle: TextStyle(),
......@@ -3535,6 +3593,7 @@ void main() {
'hintStyle: TextStyle(<all styles inherited>)',
'errorMaxLines: 5',
'hasFloatingPlaceholder: false',
'floatingLabelBehavior: FloatingLabelBehavior.never',
'contentPadding: EdgeInsetsDirectional(40.0, 12.0, 0.0, 12.0)',
'prefixStyle: TextStyle(<all styles inherited>)',
'suffixStyle: TextStyle(<all styles inherited>)',
......
......@@ -6565,7 +6565,7 @@ void main() {
expect(description, <String>[
'enabled: false',
'decoration: InputDecoration(labelText: "foo")',
'decoration: InputDecoration(labelText: "foo", floatingLabelBehavior: FloatingLabelBehavior.auto)',
'style: TextStyle(inherit: true, color: Color(0xff00ff00))',
'autofocus: true',
'autocorrect: false',
......
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