From 142922deb41f789c2ce5c19014e5ace81c8ab7d0 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 20 Mar 2017 13:32:00 -0700 Subject: [PATCH] Add WidgetTester.hasRunningAnimation (#8886) Fixes #4017 --- packages/flutter_test/lib/src/widget_tester.dart | 7 ++++++- .../flutter_test/test/widget_tester_test.dart | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 8d127c7155..9b43aff3e8 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -222,10 +222,15 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker do { await binding.pump(duration, phase); count += 1; - } while (binding.transientCallbackCount > 0); + } while (hasRunningAnimations); }).then((Null _) => count); } + /// Whether ther are any any transient callbacks scheduled. + /// + /// This essentially checks whether all animations have completed. + bool get hasRunningAnimations => binding.transientCallbackCount > 0; + @override HitTestResult hitTestOnBinding(Point location) { location = binding.localToGlobal(location); diff --git a/packages/flutter_test/test/widget_tester_test.dart b/packages/flutter_test/test/widget_tester_test.dart index e4253f7a84..9bf278b382 100644 --- a/packages/flutter_test/test/widget_tester_test.dart +++ b/packages/flutter_test/test/widget_tester_test.dart @@ -185,4 +185,20 @@ void main() { ); }); }); + + testWidgets('hasRunningAnimations control test', (WidgetTester tester) async { + final AnimationController controller = new AnimationController( + duration: const Duration(seconds: 1), + vsync: const TestVSync() + ); + expect(tester.hasRunningAnimations, isFalse); + controller.forward(); + expect(tester.hasRunningAnimations, isTrue); + controller.stop(); + expect(tester.hasRunningAnimations, isFalse); + controller.forward(); + expect(tester.hasRunningAnimations, isTrue); + await tester.pumpAndSettle(); + expect(tester.hasRunningAnimations, isFalse); + }); }