Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect argument matching in notifyOutgoingListeners #394

Closed
vulpeep opened this issue Sep 21, 2024 · 0 comments
Closed

Incorrect argument matching in notifyOutgoingListeners #394

vulpeep opened this issue Sep 21, 2024 · 0 comments
Labels

Comments

@vulpeep
Copy link

vulpeep commented Sep 21, 2024

I encountered an issue in the notifyOutgoingListeners method (located in lib/src/socket.dart on line 318).

Here's the listener code I used:

socket.onAnyOutgoing((event, data) {
});

And here's the error I got:

NoSuchMethodError: Closure call with mismatched arguments: function 'SocketIoManager._initSocketListeners.<anonymous closure>'
Receiver: Closure: (String, dynamic) => Null
Tried calling: SocketIoManager._initSocketListeners.<anonymous closure>(Instance(length:2) of '_GrowableList')
Found: SocketIoManager._initSocketListeners.<anonymous closure>(String, dynamic) => Null

The issue seems to happen because of how arguments are passed in this part of the code:

void notifyOutgoingListeners(Map packet) {
  if (_anyOutgoingListeners.isNotEmpty) {
    final listeners = List.from(_anyOutgoingListeners);
    for (final listener in listeners) {
      Function.apply(listener, [packet['data']]);
    }
  }
}

Right now, the arguments are wrapped in square brackets ([packet['data']]), which causes the mismatch. If I remove the brackets, the error goes away, and everything works fine:

void notifyOutgoingListeners(Map packet) {
  if (_anyOutgoingListeners.isNotEmpty) {
    final listeners = List.from(_anyOutgoingListeners);
    for (final listener in listeners) {
      Function.apply(listener, packet['data']);
    }
  }
}

Steps to Reproduce:

  1. Add a listener using onAnyOutgoing.
  2. Send any outgoing event.
  3. The error will occur due to argument mismatch.

Solution:
Removing the square brackets around packet['data'] in the notifyOutgoingListeners method fixes the issue and passes the arguments correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants