对于测试,我需要在表单输入中模拟使用输入。我试过创建一个 KeyboardEvent
并在输入上发送它,但这似乎不起作用。是否有 Element.click()
的等价物?躲在某个地方?
最佳答案
您在使用 WidgetTester
图书馆?
有了它,您可以在textFields
上模拟输入文本。与 enterText
方法和查找器来定位所需的textField
:
testWidgets('Add and remove a todo', (WidgetTester tester) async {
// Build the widget
await tester.pumpWidget(const TodoList());
// Enter 'hi' into the TextField.
await tester.enterText(find.byType(TextField), 'hi');
});
字体:https://flutter.dev/docs/cookbook/testing/widget/tap-drag
关于dart - 如何模拟按键事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17256217/