signalr_flutter
signalr_flutter copied to clipboard
hubCallback method not working in flutter android and .net signalr2
I am having some problems getting the hub callback method to trigger in flutter.
I am able to connect to the signalr server and send a message to the server, but on the broadcastMessage it does not hit the flutter client hubcallback.
Please see my code below.
Flutter / Android:
Future<void> initPlatformState() async {
signalR = SignalR(
"ServerURL",
"ChatHub",
hubMethods: ["broadcastMessage"],
statusChangeCallback: _onStatusChange,
hubCallback: _onNewMessage);
}
_onNewMessage(String? methodName, dynamic message) {
print('MethodName = $methodName, Message = $message');
}
_buttonTapped() async {
await signalR.invokeMethod("Send", arguments: <dynamic>["Name", "Message"]).catchError((error) {
print(error.toString());
});
}
ChatHub Server :
using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace SignalRChat
{
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
}
}
I also have the same problem, do you have a solution? @Zafoid
I also have the same problem, but everything is normal in the debug environment, and the release version received hubCallback @AyonAB @Zafoid @rsyd29 @mohas