showKeyboard method

Future<void> showKeyboard(
  1. FinderBase<Element> finder

Give the text input widget specified by finder the focus, as if the onscreen keyboard had appeared.

Implies a call to pump.

The widget specified by finder must be an EditableText or have an EditableText descendant. For example find.byType(TextField) or find.byType(TextFormField), or find.byType(EditableText).

Tests that just need to add text to widgets like TextField or TextFormField only need to call enterText.


Future<void> showKeyboard(FinderBase<Element> finder) async {
  bool skipOffstage = true;
  if (finder is Finder) {
    skipOffstage = finder.skipOffstage;
  return TestAsyncUtils.guard<void>(() async {
    final EditableTextState editable = state<EditableTextState>(
        of: finder,
        matching: find.byType(EditableText, skipOffstage: skipOffstage),
        matchRoot: true,
    // Setting focusedEditable causes the binding to call requestKeyboard()
    // on the EditableTextState, which itself eventually calls TextInput.attach
    // to establish the connection.
    binding.focusedEditable = editable;
    await pump();