How to mimic a pressing ENTER on a TextField in Flutter Tests

感情迁移 提交于 2019-12-10 15:59:05

问题


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?

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


回答1:


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:

ex: await 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();


来源:https://stackoverflow.com/questions/54538603/how-to-mimic-a-pressing-enter-on-a-textfield-in-flutter-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!