Newly constructed tweens should have same begin and end (#94363)
This commit is contained in:
parent
7b8df6e415
commit
aa5d7b6972
@ -429,6 +429,8 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget>
|
|||||||
tween ??= constructor(targetValue);
|
tween ??= constructor(targetValue);
|
||||||
if (_shouldAnimateTween(tween, targetValue))
|
if (_shouldAnimateTween(tween, targetValue))
|
||||||
shouldStartAnimation = true;
|
shouldStartAnimation = true;
|
||||||
|
else
|
||||||
|
tween.end ??= tween.begin;
|
||||||
} else {
|
} else {
|
||||||
tween = null;
|
tween = null;
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedPadding onEnd callback test', (WidgetTester tester) async {
|
testWidgets('AnimatedPadding onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -106,6 +108,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedAlign onEnd callback test', (WidgetTester tester) async {
|
testWidgets('AnimatedAlign onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -127,6 +131,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedPositioned onEnd callback test', (WidgetTester tester) async {
|
testWidgets('AnimatedPositioned onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -148,6 +154,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedPositionedDirectional onEnd callback test', (WidgetTester tester) async {
|
testWidgets('AnimatedPositionedDirectional onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -169,6 +177,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedSlide onEnd callback test', (WidgetTester tester) async {
|
testWidgets('AnimatedSlide onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -189,6 +199,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedSlide transition test', (WidgetTester tester) async {
|
testWidgets('AnimatedSlide transition test', (WidgetTester tester) async {
|
||||||
@ -247,6 +259,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedScale transition test', (WidgetTester tester) async {
|
testWidgets('AnimatedScale transition test', (WidgetTester tester) async {
|
||||||
@ -305,6 +319,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedRotation transition test', (WidgetTester tester) async {
|
testWidgets('AnimatedRotation transition test', (WidgetTester tester) async {
|
||||||
@ -363,6 +379,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedOpacity transition test', (WidgetTester tester) async {
|
testWidgets('AnimatedOpacity transition test', (WidgetTester tester) async {
|
||||||
@ -421,6 +439,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('SliverAnimatedOpacity transition test', (WidgetTester tester) async {
|
testWidgets('SliverAnimatedOpacity transition test', (WidgetTester tester) async {
|
||||||
@ -480,6 +500,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedPhysicalModel onEnd callback test', (WidgetTester tester) async {
|
testWidgets('AnimatedPhysicalModel onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -501,6 +523,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TweenAnimationBuilder onEnd callback test', (WidgetTester tester) async {
|
testWidgets('TweenAnimationBuilder onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -522,6 +546,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AnimatedTheme onEnd callback test', (WidgetTester tester) async {
|
testWidgets('AnimatedTheme onEnd callback test', (WidgetTester tester) async {
|
||||||
@ -543,6 +569,8 @@ void main() {
|
|||||||
expect(mockOnEndFunction.called, 0);
|
expect(mockOnEndFunction.called, 0);
|
||||||
await tester.pump(additionalDelay);
|
await tester.pump(additionalDelay);
|
||||||
expect(mockOnEndFunction.called, 1);
|
expect(mockOnEndFunction.called, 1);
|
||||||
|
|
||||||
|
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Ensure CurvedAnimations are disposed on widget change',
|
testWidgets('Ensure CurvedAnimations are disposed on widget change',
|
||||||
@ -599,6 +627,21 @@ void main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> tapTest2and3(WidgetTester tester, Finder widgetFinder,
|
||||||
|
MockOnEndFunction mockOnEndFunction) async {
|
||||||
|
await tester.tap(widgetFinder);
|
||||||
|
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(animationDuration + additionalDelay);
|
||||||
|
expect(mockOnEndFunction.called, 2);
|
||||||
|
|
||||||
|
await tester.tap(widgetFinder);
|
||||||
|
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(animationDuration + additionalDelay);
|
||||||
|
expect(mockOnEndFunction.called, 3);
|
||||||
|
}
|
||||||
|
|
||||||
Widget wrap({required Widget child}) {
|
Widget wrap({required Widget child}) {
|
||||||
return Directionality(
|
return Directionality(
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
@ -664,6 +707,7 @@ class _TestAnimatedContainerWidgetState extends _TestAnimatedWidgetState {
|
|||||||
duration: duration,
|
duration: duration,
|
||||||
onEnd: widget.callback,
|
onEnd: widget.callback,
|
||||||
width: toggle ? 10 : 20,
|
width: toggle ? 10 : 20,
|
||||||
|
foregroundDecoration: toggle ? const BoxDecoration() : null,
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -835,7 +879,7 @@ class _TestTweenAnimationBuilderWidgetState extends _TestAnimatedWidgetState {
|
|||||||
@override
|
@override
|
||||||
Widget getAnimatedWidget() {
|
Widget getAnimatedWidget() {
|
||||||
return TweenAnimationBuilder<double>(
|
return TweenAnimationBuilder<double>(
|
||||||
tween: Tween<double>(begin: 1, end: 2),
|
tween: toggle ? Tween<double>(begin: 1, end: 2) : Tween<double>(begin: 2, end: 1),
|
||||||
duration: duration,
|
duration: duration,
|
||||||
onEnd: widget.callback,
|
onEnd: widget.callback,
|
||||||
child: child,
|
child: child,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user