simulateKeyUpEvent function

Future<bool> simulateKeyUpEvent(
  1. LogicalKeyboardKey key,
  2. {String? platform,
  3. PhysicalKeyboardKey? physicalKey}
)

Simulates sending a hardware key up event through the system channel.

It is intended for use in writing tests.

This only simulates key presses coming from a physical keyboard, not from a soft keyboard, and it can only simulate keys that appear in the key maps such as kAndroidToLogicalKey, kMacOsToPhysicalKey, etc.

Specify platform as one of the platforms allowed in Platform.operatingSystem to make the event appear to be from that type of system. Defaults to the operating system that the test is running on.

Returns true if the key event was handled by the framework.

See also:

Implementation

Future<bool> simulateKeyUpEvent(
  LogicalKeyboardKey key, {
  String? platform,
  PhysicalKeyboardKey? physicalKey,
}) async {
  final bool handled = await KeyEventSimulator.simulateKeyUpEvent(key, platform: platform, physicalKey: physicalKey);
  final ServicesBinding binding = ServicesBinding.instance;
  if (!handled && binding is TestWidgetsFlutterBinding) {
    await binding.testTextInput.handleKeyUpEvent(key);
  }
  return handled;
}