diff --git a/packages/flutter_test/lib/src/controller.dart b/packages/flutter_test/lib/src/controller.dart index d350c0bc98..f2081f16ae 100644 --- a/packages/flutter_test/lib/src/controller.dart +++ b/packages/flutter_test/lib/src/controller.dart @@ -423,7 +423,11 @@ abstract class WidgetController { /// See [PointerEventRecord]. Future> handlePointerEventRecord(List records); - /// Called to indicate that time should advance. + /// Called to indicate that there should be a new frame after an optional + /// delay. + /// + /// The frame is pumped after a delay of [duration] if [duration] is not null, + /// or immediately otherwise. /// /// This is invoked by [flingFrom], for instance, so that the sequence of /// pointer events occurs over time. @@ -432,7 +436,7 @@ abstract class WidgetController { /// /// See also [SchedulerBinding.endOfFrame], which returns a future that could /// be appropriate to return in the implementation of this method. - Future pump(Duration duration); + Future pump([Duration duration]); /// Attempts to drag the given widget by the given offset, by /// starting a drag in the middle of the widget. @@ -755,7 +759,7 @@ class LiveWidgetController extends WidgetController { LiveWidgetController(WidgetsBinding binding) : super(binding); @override - Future pump(Duration duration) async { + Future pump([Duration duration]) async { if (duration != null) await Future.delayed(duration); binding.scheduleFrame(); diff --git a/packages/flutter_test/test/live_widget_controller_test.dart b/packages/flutter_test/test/live_widget_controller_test.dart index 764aef640d..68ce1b70eb 100644 --- a/packages/flutter_test/test/live_widget_controller_test.dart +++ b/packages/flutter_test/test/live_widget_controller_test.dart @@ -9,7 +9,41 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_test/flutter_test.dart'; -Future main() async { +class CountButton extends StatefulWidget { + @override + _CountButtonState createState() => _CountButtonState(); +} + +class _CountButtonState extends State { + int counter = 0; + @override + Widget build(BuildContext context) { + return RaisedButton( + child: Text('Counter $counter'), + onPressed: () { + setState(() { + counter += 1; + }); + }, + ); + } +} + +void main() { + test('Test pump on LiveWidgetController', () async { + runApp(MaterialApp(home: Center(child: CountButton()))); + + await SchedulerBinding.instance.endOfFrame; + final WidgetController controller = + LiveWidgetController(WidgetsBinding.instance); + await controller.tap(find.text('Counter 0')); + expect(find.text('Counter 0'), findsOneWidget); + expect(find.text('Counter 1'), findsNothing); + await controller.pump(); + expect(find.text('Counter 0'), findsNothing); + expect(find.text('Counter 1'), findsOneWidget); + }); + test('Input event array on LiveWidgetController', () async { final List logs = []; runApp(