import 'package:flutter/services.dart';
import 'package:get/get.dart';

mixin EnterPressListenOnControllerMixin on GetxController {
  @override
  void onReady() {
    RawKeyboard.instance.addListener(_listenKeyboardEvent);
    super.onReady();
  }

  @override
  void onClose() {
    RawKeyboard.instance.removeListener(_listenKeyboardEvent);
    super.onClose();
  }

  void _listenKeyboardEvent(RawKeyEvent event) {
    if (event.logicalKey.keyLabel == 'Enter' ||
        event.logicalKey.keyLabel == 'Numpad Enter') {
      onEnterPressed();
    }
  }

  void onEnterPressed();
}
