WidgetController.pump use optional duration (#62091)
This commit is contained in:
@@ -423,7 +423,11 @@ abstract class WidgetController {
|
||||
/// See [PointerEventRecord].
|
||||
Future<List<Duration>> handlePointerEventRecord(List<PointerEventRecord> 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<void> pump(Duration duration);
|
||||
Future<void> 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<void> pump(Duration duration) async {
|
||||
Future<void> pump([Duration duration]) async {
|
||||
if (duration != null)
|
||||
await Future<void>.delayed(duration);
|
||||
binding.scheduleFrame();
|
||||
|
||||
@@ -9,7 +9,41 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
class CountButton extends StatefulWidget {
|
||||
@override
|
||||
_CountButtonState createState() => _CountButtonState();
|
||||
}
|
||||
|
||||
class _CountButtonState extends State<CountButton> {
|
||||
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<String> logs = <String>[];
|
||||
runApp(
|
||||
|
||||
Reference in New Issue
Block a user