withShiftEnter method
FocusNode
withShiftEnter({
- required void onSubmit(),
- required TextEditingController controller,
- 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;
}