Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 813
xpeldev Avatar asked Feb 05 '19 16:02

xpeldev


Video Answer


1 Answers

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();
like image 81
xpeldev Avatar answered Sep 30 '22 03:09

xpeldev