Unverified Commit aa5d7b69 authored by Viren Khatri's avatar Viren Khatri Committed by GitHub

Newly constructed tweens should have same begin and end (#94363)

parent 7b8df6e4
...@@ -429,6 +429,8 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget> ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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 { ...@@ -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 { ...@@ -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,
......
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