25

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

xpeldev
  • 1,812
  • 2
  • 12
  • 23

1 Answers1

53

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();
xpeldev
  • 1,812
  • 2
  • 12
  • 23