showKeyboard method Null safety

Future<void> showKeyboard(
  1. Finder 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.

Implementation

Future<void> showKeyboard(Finder finder) async {
  return TestAsyncUtils.guard<void>(() async {
    final EditableTextState editable = state<EditableTextState>(
      find.descendant(
        of: finder,
        matching: find.byType(EditableText, skipOffstage: finder.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();
  });
}