Fix behavior change due to incorrect initial floating setting (#55651)

This commit is contained in:
Mehmet Fidanboylu 2020-04-28 10:44:03 -07:00 committed by GitHub
parent 6cf9c7cc17
commit eddba97d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -1915,8 +1915,10 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
super.initState();
final bool labelIsInitiallyFloating = widget.decoration.floatingLabelBehavior == FloatingLabelBehavior.always
// ignore: deprecated_member_use_from_same_package
|| (widget.decoration.hasFloatingPlaceholder && widget._labelShouldWithdraw);
|| (widget.decoration.floatingLabelBehavior != FloatingLabelBehavior.never &&
// ignore: deprecated_member_use_from_same_package
widget.decoration.hasFloatingPlaceholder &&
widget._labelShouldWithdraw);
_floatingLabelController = AnimationController(
duration: _kTransitionDuration,

View File

@ -3910,4 +3910,18 @@ void main() {
expect(tester.getTopLeft(find.text('label')).dy, -4.0);
});
testWidgets('InputDecorator floating label obeys floatingLabelBehavior', (WidgetTester tester) async {
await tester.pumpWidget(
buildInputDecorator(
decoration: const InputDecoration(
labelText: 'label',
floatingLabelBehavior: FloatingLabelBehavior.never,
),
),
);
// Passing floating behavior never results in a dy offset of 20
// because the label is not initially floating.
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
});
}