insertText static method

Future insertText(
  1. String text
)

Inserts text into a text input field.

This function simulates entering text into a text input field by invoking platform channel methods. It updates the editing state of the text input field to reflect the provided text.

Example:

Offset? inputOffset = EaseSimulator.getWidgetOffset(key);
await EaseSimulator.tap(offset);
await EaseSimulator.insertText("user_name");

Implementation

static Future insertText(String text) async {
  await Future.delayed(const Duration(milliseconds: 750));
  WidgetsBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
    SystemChannels.textInput.name,
    SystemChannels.textInput.codec.encodeMethodCall(
      MethodCall(
        'TextInputClient.updateEditingState',
        <dynamic>[
          1,
          TextEditingValue(
            text: text,
            selection: TextSelection.collapsed(offset: text.length),
          ).toJSON()
        ],
      ),
    ),
    (data) {},
  );

  EaseDevice.hideKeyboard();

  await Future.delayed(const Duration(milliseconds: 750));
}