Unable to receive messages and incoming events using Quckblox and Flutter

Viewed 275

I have tried the sample code provided by QB but event subscription is not working and the method body is never executed. I am attaching my code for reference

subscribeToEvent() async {

try {
  await QB.chat.subscribeMessageEvents( QBChatEvents.RECEIVED_NEW_MESSAGE, (data) {

    print("dbee inside event subscribeMessageEvents");
    Map<String, Object> map = new Map<String, dynamic>.from(data);
    String messageType = map["type"];
    String messageBody = "system message";
    if (messageType == QBChatEvents.RECEIVED_NEW_MESSAGE) {
      Map<String, Object> payload =
      new Map<String, dynamic>.from(map["payload"]);
      messageBody = payload["body"];
      String messageId = payload["id"];
      print("dbee $messageBody $messageId");
    }
  }, );
} on Exception catch (e) {
  print("Error in subscribing");
  print(e);
}

I can see the XMPP logs being printed on console when a new message comes but the subscriber is never invoked.

1 Answers

Make sure you are using the latest version of QuickBlox Flutter SDK: 0.2.3-alpha .

Next, follow the below steps:

  • Settings => init credentials
  • Auth => login
  • Chat => connect
  • Chat => subscribe message events
  • Chat => send message

Please note that outgoing messages will also appear in the callback QBChatEvents.RECEIVED_NEW_MESSAGE.

Related