如何在Flutter测试中模拟TextField上的Enter键 [英] How to mimic a pressing ENTER on a TextField in Flutter Tests

查看:418
本文介绍了如何在Flutter测试中模拟TextField上的Enter键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于 tester.enterText 将允许我在抖动测试中在 TextField 上输入文本,如何我会模拟在Android键盘上按 Done 键还是在文本字段内按键盘上的 ENTER

Given that tester.enterText will allow me to enter the text on a TextField in a flutter test, how would I mock pressing the DONE key on the android keyboard or pressing ENTER on my keyboard inside the textfield?

这也等同于检查IOS / Android键盘上的 Done 按钮是否按下

This would also be equivalent to checking for the pressing of the DONE button on the IOS/android keyboard

推荐答案

我在flutter回购测试中找到了该实现@ @ noreferrer> https://github.com/flutter/flutter/blob/7e445a17324ee7e615ef2c886d0cb9407853f338/packages/flutter/test/widgets/editable_text_test.dart#L558 :

I found the implementation in the flutter repo tests @ https://github.com/flutter/flutter/blob/7e445a17324ee7e615ef2c886d0cb9407853f338/packages/flutter/test/widgets/editable_text_test.dart#L558:

例如:等待tester.testTextInput.receiveAction(TextInputAction.done);

// example
await tester.enterText(find.byKey(new Key('txtFieldKey')), 'Hello World!');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pump();

这篇关于如何在Flutter测试中模拟TextField上的Enter键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆