soernt / signalr_client

A Flutter SignalR Client for ASP.NET Core
MIT License
131 stars 203 forks source link

How to pass complex object as parameter #5

Closed sherifhasan closed 5 years ago

sherifhasan commented 5 years ago

The following code throws Converting object to an encodable object failed: Instance of 'InvocationMessage'

_hubConnection.invoke("Broadcast", args: [request, broadMessage]);

I already implemented toJson() as per instruction use objects that implements toJson() since that method is used by the dart:convert package to serialize an object. here https://pub.dartlang.org/packages/signalr_client

class NotificationRequest {
  int connectionType;
  String command;
  int userId;
  String userName;
  String uuid;

  NotificationRequest(
      {this.command,
      this.connectionType,
      this.userId,
      this.userName,
      this.uuid});

  Map<String, dynamic> toJson() => {
        'connectionType': connectionType,
        'command': command,
        'userId': userId,
        'userName': userName,
        'uuid': uuid
      };
}
class BroadCastMessage {
  String message;
  BroadCastMessage({this.message});
  Map<String, dynamic> toJson() => {'message': message};
}
soernt commented 5 years ago

This should be fixed within the new version 0.1.5. Thank you for reporting the bug! There is a test for this.