withShiftEnter method

FocusNode withShiftEnter({
  1. required void onSubmit(
    1. String
    ),
  2. required TextEditingController controller,
  3. bool autoClear = true,
})

Implementation

FocusNode withShiftEnter(
    {required void Function(String) onSubmit,
    required TextEditingController controller,
    bool autoClear = true}) {
  onKeyEvent = (FocusNode node, KeyEvent key) {
    if (!HardwareKeyboard.instance.isShiftPressed &&
        key.logicalKey.keyLabel == 'Enter') {
      if (key is KeyDownEvent || key is KeyRepeatEvent) {
        onSubmit(controller.text);
        if (autoClear) {
          controller.clear();
        }
      }
      return KeyEventResult.handled;
    }

    return KeyEventResult.ignored;
  };

  return this;
}