Skip to content

Commit 9f6090c

Browse files
author
Casey Hillers
authored
Revert "Fix text field label animation duration and curve" (#114646)
* Revert "Fix text field label animation duration and curve (#105966)" This reverts commit d5c53b8. * Add doubleTapTimer.cancel back
1 parent 125b9a7 commit 9f6090c

File tree

2 files changed

+23
-81
lines changed

2 files changed

+23
-81
lines changed

packages/flutter/lib/src/material/input_decorator.dart

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import 'theme_data.dart';
2222
// Examples can assume:
2323
// late Widget _myIcon;
2424

25-
// The duration value extracted from:
26-
// https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/TextInputLayout.java
27-
const Duration _kTransitionDuration = Duration(milliseconds: 167);
25+
const Duration _kTransitionDuration = Duration(milliseconds: 200);
2826
const Curve _kTransitionCurve = Curves.fastOutSlowIn;
2927
const double _kFinalLabelScale = 0.75;
3028

@@ -194,7 +192,6 @@ class _BorderContainerState extends State<_BorderContainer> with TickerProviderS
194192
_borderAnimation = CurvedAnimation(
195193
parent: _controller,
196194
curve: _kTransitionCurve,
197-
reverseCurve: _kTransitionCurve.flipped,
198195
);
199196
_border = _InputBorderTween(
200197
begin: widget.border,
@@ -1869,9 +1866,8 @@ class InputDecorator extends StatefulWidget {
18691866
}
18701867

18711868
class _InputDecoratorState extends State<InputDecorator> with TickerProviderStateMixin {
1872-
late final AnimationController _floatingLabelController;
1873-
late final Animation<double> _floatingLabelAnimation;
1874-
late final AnimationController _shakingLabelController;
1869+
late AnimationController _floatingLabelController;
1870+
late AnimationController _shakingLabelController;
18751871
final _InputBorderGap _borderGap = _InputBorderGap();
18761872

18771873
@override
@@ -1888,11 +1884,6 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
18881884
value: labelIsInitiallyFloating ? 1.0 : 0.0,
18891885
);
18901886
_floatingLabelController.addListener(_handleChange);
1891-
_floatingLabelAnimation = CurvedAnimation(
1892-
parent: _floatingLabelController,
1893-
curve: _kTransitionCurve,
1894-
reverseCurve: _kTransitionCurve.flipped,
1895-
);
18961887

18971888
_shakingLabelController = AnimationController(
18981889
duration: _kTransitionDuration,
@@ -2170,7 +2161,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
21702161
final Widget container = _BorderContainer(
21712162
border: border,
21722163
gap: _borderGap,
2173-
gapAnimation: _floatingLabelAnimation,
2164+
gapAnimation: _floatingLabelController.view,
21742165
fillColor: _getFillColor(themeData, defaults),
21752166
hoverColor: _getHoverColor(themeData),
21762167
isHovering: isHovering,
@@ -2350,7 +2341,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
23502341
isCollapsed: decoration.isCollapsed,
23512342
floatingLabelHeight: floatingLabelHeight,
23522343
floatingLabelAlignment: decoration.floatingLabelAlignment!,
2353-
floatingLabelProgress: _floatingLabelAnimation.value,
2344+
floatingLabelProgress: _floatingLabelController.value,
23542345
border: border,
23552346
borderGap: _borderGap,
23562347
alignLabelWithHint: decoration.alignLabelWithHint ?? false,

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 18 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void main() {
265265
);
266266

267267
// The label animates downwards from it's initial position
268-
// above the input text. The animation's duration is 167ms.
268+
// above the input text. The animation's duration is 200ms.
269269
{
270270
await tester.pump(const Duration(milliseconds: 50));
271271
final double labelY50ms = tester.getTopLeft(find.text('label')).dy;
@@ -296,7 +296,7 @@ void main() {
296296
);
297297

298298
// The label animates upwards from it's initial position
299-
// above the input text. The animation's duration is 167ms.
299+
// above the input text. The animation's duration is 200ms.
300300
await tester.pump(const Duration(milliseconds: 50));
301301
final double labelY50ms = tester.getTopLeft(find.text('label')).dy;
302302
expect(labelY50ms, inExclusiveRange(12.0, 28.0));
@@ -563,7 +563,7 @@ void main() {
563563
);
564564

565565
// The label animates downwards from it's initial position
566-
// above the input text. The animation's duration is 167ms.
566+
// above the input text. The animation's duration is 200ms.
567567
await tester.pump(const Duration(milliseconds: 50));
568568
final double labelY50ms = tester.getTopLeft(find.byKey(key)).dy;
569569
expect(labelY50ms, inExclusiveRange(12.0, 20.0));
@@ -604,7 +604,7 @@ void main() {
604604
);
605605

606606
// The label animates upwards from it's initial position
607-
// above the input text. The animation's duration is 167ms.
607+
// above the input text. The animation's duration is 200ms.
608608
{
609609
await tester.pump(const Duration(milliseconds: 50));
610610
final double labelY50ms = tester.getTopLeft(find.byKey(key)).dy;
@@ -720,55 +720,6 @@ void main() {
720720

721721
});
722722

723-
testWidgets('InputDecorator floating label animation duration and curve', (WidgetTester tester) async {
724-
Future<void> pumpInputDecorator({
725-
required bool isFocused,
726-
}) async {
727-
return tester.pumpWidget(
728-
buildInputDecorator(
729-
isEmpty: true,
730-
isFocused: isFocused,
731-
decoration: const InputDecoration(
732-
labelText: 'label',
733-
floatingLabelBehavior: FloatingLabelBehavior.auto,
734-
),
735-
),
736-
);
737-
}
738-
await pumpInputDecorator(isFocused: false);
739-
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
740-
741-
// The label animates upwards and scales down.
742-
// The animation duration is 167ms and the curve is fastOutSlowIn.
743-
await pumpInputDecorator(isFocused: true);
744-
await tester.pump(const Duration(milliseconds: 42));
745-
expect(tester.getTopLeft(find.text('label')).dy, closeTo(18.06, 0.5));
746-
await tester.pump(const Duration(milliseconds: 42));
747-
expect(tester.getTopLeft(find.text('label')).dy, closeTo(13.78, 0.5));
748-
await tester.pump(const Duration(milliseconds: 42));
749-
expect(tester.getTopLeft(find.text('label')).dy, closeTo(12.31, 0.5));
750-
await tester.pump(const Duration(milliseconds: 41));
751-
expect(tester.getTopLeft(find.text('label')).dy, 12.0);
752-
753-
// If the animation changes direction without first reaching the
754-
// AnimationStatus.completed or AnimationStatus.dismissed status,
755-
// the CurvedAnimation stays on the same curve in the opposite direction.
756-
// The pumpAndSettle is used to prevent this behavior.
757-
await tester.pumpAndSettle();
758-
759-
// The label animates downwards and scales up.
760-
// The animation duration is 167ms and the curve is fastOutSlowIn.
761-
await pumpInputDecorator(isFocused: false);
762-
await tester.pump(const Duration(milliseconds: 42));
763-
expect(tester.getTopLeft(find.text('label')).dy, closeTo(13.94, 0.5));
764-
await tester.pump(const Duration(milliseconds: 42));
765-
expect(tester.getTopLeft(find.text('label')).dy, closeTo(18.22, 0.5));
766-
await tester.pump(const Duration(milliseconds: 42));
767-
expect(tester.getTopLeft(find.text('label')).dy, closeTo(19.69, 0.5));
768-
await tester.pump(const Duration(milliseconds: 41));
769-
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
770-
});
771-
772723
group('alignLabelWithHint', () {
773724
group('expands false', () {
774725
testWidgets('multiline TextField no-strut', (WidgetTester tester) async {
@@ -1062,7 +1013,7 @@ void main() {
10621013
);
10631014

10641015
// The hint's opacity animates from 0.0 to 1.0.
1065-
// The animation's duration is 167ms.
1016+
// The animation's duration is 200ms.
10661017
{
10671018
await tester.pump(const Duration(milliseconds: 50));
10681019
final double hintOpacity50ms = getOpacity(tester, 'hint');
@@ -1096,7 +1047,7 @@ void main() {
10961047
);
10971048

10981049
// The hint's opacity animates from 1.0 to 0.0.
1099-
// The animation's duration is 167ms.
1050+
// The animation's duration is 200ms.
11001051
{
11011052
await tester.pump(const Duration(milliseconds: 50));
11021053
final double hintOpacity50ms = getOpacity(tester, 'hint');
@@ -2017,7 +1968,7 @@ void main() {
20171968
);
20181969

20191970
// The hint's opacity animates from 0.0 to 1.0.
2020-
// The animation's duration is 167ms.
1971+
// The animation's duration is 200ms.
20211972
{
20221973
await tester.pump(const Duration(milliseconds: 50));
20231974
final double hintOpacity50ms = getOpacity(tester, 'hint');
@@ -2052,7 +2003,7 @@ void main() {
20522003
);
20532004

20542005
// The hint's opacity animates from 1.0 to 0.0.
2055-
// The animation's duration is 167ms.
2006+
// The animation's duration is 200ms.
20562007
{
20572008
await tester.pump(const Duration(milliseconds: 50));
20582009
final double hintOpacity50ms = getOpacity(tester, 'hint');
@@ -2114,7 +2065,7 @@ void main() {
21142065
);
21152066

21162067
// The hint's opacity animates from 0.0 to 1.0.
2117-
// The animation's duration is 167ms.
2068+
// The animation's duration is 200ms.
21182069
{
21192070
await tester.pump(const Duration(milliseconds: 50));
21202071
final double hintOpacity50ms = getOpacity(tester, 'hint');
@@ -2149,7 +2100,7 @@ void main() {
21492100
);
21502101

21512102
// The hint's opacity animates from 1.0 to 0.0.
2152-
// The animation's duration is 167ms.
2103+
// The animation's duration is 200ms.
21532104
{
21542105
await tester.pump(const Duration(milliseconds: 50));
21552106
final double hintOpacity50ms = getOpacity(tester, 'hint');
@@ -4463,17 +4414,17 @@ void main() {
44634414

44644415
await pumpDecorator(hovering: true, filled: false);
44654416
expect(getBorderColor(tester), equals(enabledBorderColor));
4466-
await tester.pump(const Duration(milliseconds: 167));
4417+
await tester.pump(const Duration(milliseconds: 200));
44674418
expect(getBorderColor(tester), equals(blendedHoverColor));
44684419

44694420
await pumpDecorator(hovering: false, filled: false);
44704421
expect(getBorderColor(tester), equals(blendedHoverColor));
4471-
await tester.pump(const Duration(milliseconds: 167));
4422+
await tester.pump(const Duration(milliseconds: 200));
44724423
expect(getBorderColor(tester), equals(enabledBorderColor));
44734424

44744425
await pumpDecorator(hovering: false, filled: false, enabled: false);
44754426
expect(getBorderColor(tester), equals(enabledBorderColor));
4476-
await tester.pump(const Duration(milliseconds: 167));
4427+
await tester.pump(const Duration(milliseconds: 200));
44774428
expect(getBorderColor(tester), equals(disabledColor));
44784429

44794430
await pumpDecorator(hovering: true, filled: false, enabled: false);
@@ -4517,17 +4468,17 @@ void main() {
45174468

45184469
await pumpDecorator(focused: true, filled: false);
45194470
expect(getBorderColor(tester), equals(enabledBorderColor));
4520-
await tester.pump(const Duration(milliseconds: 167));
4471+
await tester.pump(const Duration(milliseconds: 200));
45214472
expect(getBorderColor(tester), equals(focusColor));
45224473

45234474
await pumpDecorator(focused: false, filled: false);
45244475
expect(getBorderColor(tester), equals(focusColor));
4525-
await tester.pump(const Duration(milliseconds: 167));
4476+
await tester.pump(const Duration(milliseconds: 200));
45264477
expect(getBorderColor(tester), equals(enabledBorderColor));
45274478

45284479
await pumpDecorator(focused: false, filled: false, enabled: false);
45294480
expect(getBorderColor(tester), equals(enabledBorderColor));
4530-
await tester.pump(const Duration(milliseconds: 167));
4481+
await tester.pump(const Duration(milliseconds: 200));
45314482
expect(getBorderColor(tester), equals(disabledColor));
45324483

45334484
await pumpDecorator(focused: true, filled: false, enabled: false);
@@ -5611,8 +5562,8 @@ void main() {
56115562

56125563
// Click for Focus.
56135564
await tester.tap(find.byType(TextField));
5614-
// Default animation duration is 167ms.
5615-
await tester.pumpFrames(target, const Duration(milliseconds: 80));
5565+
// Default animation duration is 200 millisecond.
5566+
await tester.pumpFrames(target, const Duration(milliseconds: 100));
56165567

56175568
expect(getLabelRect(tester).width, greaterThan(labelWidth));
56185569
expect(getLabelRect(tester).width, lessThanOrEqualTo(floatedLabelWidth));

0 commit comments

Comments
 (0)