dart - 如何模拟按键事件?

标签 dart

对于测试,我需要在表单输入中模拟使用输入。我试过创建一个 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/

相关文章:

dictionary - 在流中使用 map 时出现Dart问题

angularjs - Angular Dart 和表单验证

dart - 如何使用 Homebrew 降级 Dart

firebase - 强制 Firestore 数据库缓存数据库

ssl - 使用 Golang 在 Nginx 后面运行的 GRPC 服务的 TLS

dart - 如何定义一个带有可选参数的调用 super 的构造函数?

android - 如何在 SearchDelegate 的 buildResults 中传递更新 UI 值?

compilation - Dart 中有编译器预处理器吗?

flutter - Dart:Map 类,reduce(或以其他方式查找某些信息)

dart - flutter 导航栏