merge method

InputEvents merge(
  1. InputEvents? other
)

If you have multiple InputEvents, you can merge them using this method.

Example:

final events = InputEvents(
  onInput: (e) => print('Input event!'),
  onChange: (e) => print('Change event!'),
  customEvents: {
    'customEvent': (e) => print('Custom event!'),
  },
);

final otherEvents = InputEvents(
  onInput: (e) => print('Other input event!'),
  onChange: (e) => print('Other change event!'),
  customEvents: {
    'customEvent': (e) => print('Other custom event!'),
  },
);

final mergedEvents = events.merge(otherEvents);

Implementation

InputEvents merge(InputEvents? other) {
  final effectiveOnInput = onInput != null
      ? (Event e) {
          onInput!(e);
          other?.onInput?.call(e);
        }
      : other?.onInput;

  final effectiveOnChange = onChange != null
      ? (Event e) {
          onChange!(e);
          other?.onChange?.call(e);
        }
      : other?.onChange;

  final effectiveOnSelect = onSelect != null
      ? (Event e) {
          onSelect!(e);
          other?.onSelect?.call(e);
        }
      : other?.onSelect;

  final effectiveOnFocus = onFocus != null
      ? (FocusEvent e) {
          onFocus!(e);
          other?.onFocus?.call(e);
        }
      : other?.onFocus;

  final effectiveOnFocusIn = onFocusIn != null
      ? (FocusEvent e) {
          onFocusIn!(e);
          other?.onFocusIn?.call(e);
        }
      : other?.onFocusIn;

  final effectiveOnFocusOut = onFocusOut != null
      ? (FocusEvent e) {
          onFocusOut!(e);
          other?.onFocusOut?.call(e);
        }
      : other?.onFocusOut;

  final effectiveOnBlur = onBlur != null
      ? (FocusEvent e) {
          onBlur!(e);
          other?.onBlur?.call(e);
        }
      : other?.onBlur;

  final effectiveOnInvalid = onInvalid != null
      ? (Event e) {
          onInvalid!(e);
          other?.onInvalid?.call(e);
        }
      : other?.onInvalid;

  final effectiveOnKeyDown = onKeyDown != null
      ? (KeyboardEvent e) {
          onKeyDown!(e);
          other?.onKeyDown?.call(e);
        }
      : other?.onKeyDown;

  final effectiveOnKeyUp = onKeyUp != null
      ? (KeyboardEvent e) {
          onKeyUp!(e);
          other?.onKeyUp?.call(e);
        }
      : other?.onKeyUp;

  final effectiveOnPaste = onPaste != null
      ? (ClipboardEvent e) {
          onPaste!(e);
          other?.onPaste?.call(e);
        }
      : other?.onPaste;

  final effectiveCustomEvents = customEvents != null
      ? {...customEvents!, ...?other?.customEvents}
      : other?.customEvents;

  return InputEvents(
    onInput: effectiveOnInput,
    onChange: effectiveOnChange,
    onSelect: effectiveOnSelect,
    onFocus: effectiveOnFocus,
    onFocusIn: effectiveOnFocusIn,
    onFocusOut: effectiveOnFocusOut,
    onBlur: effectiveOnBlur,
    onInvalid: effectiveOnInvalid,
    onKeyDown: effectiveOnKeyDown,
    onKeyUp: effectiveOnKeyUp,
    onPaste: effectiveOnPaste,
    customEvents: effectiveCustomEvents,
  );
}