ABP signalR Notifications not received in Flutter

Viewed 101

I'm trying to send notification from abp project using signalR and it works fine with angular but when I tried receive notification in flutter it does not work !! no notification received here is my flutter code

late HubConnection hubConnection ;
    
  @override
  void initState() {
    connect();
      super.initState();

  }
  void connect() async {
    hubConnection=  HubConnectionBuilder().withUrl(serverUrl, options: HttpConnectionOptions(
                accessTokenFactory: ()=>Api.getAccessToken())).build();
    hubConnection.start()?.then((value) => print('connected')); //prints connect successfully
    hubConnection.on('ReceiveNotificationMessage', (arguments) {
      print('notification');// doesn't print 
      print(arguments);// doesn't print 
    },);
  }

Note: I am using signalr_netcore package I also tried signalr_client package

thanks in advance

1 Answers

I solved the problem by listening to onConnect message in order to add the user to connected clients list as the code bellow:

void connect() async {
    hubConnection.start()?.then((value) => print('connected'));
     hubConnection.on('OnConnectNotificationMessage', (arguments) {
      print('notification');
      print(arguments);
    },);
    hubConnection.on('ReceiveNotificationMessage',_newmessages);
  }
Related