I'm developing a chat application using Laravel and flutter. I'm using ably_flutter package to make it realtime. The channel is created successfully but it's faild to listen an event or a message.
final clientOptions = ably.ClientOptions(
key: 'rVPjew.ydfBPA:JqRRY9JI49_L9l8CsfvMxXuxhMeyQzgEo6apWE');
subscribeAbly() async {
ably.Realtime realtime = ably.Realtime(options: clientOptions);
realtime.connection
.on(ably.ConnectionEvent.connected)
.listen((ably.ConnectionStateChange stateChange) async {
print(stateChange.current)// connected
ably.RealtimeChannel channel = realtime.channels.get('public.room');
channel.subscribe(name: 'message.new').listen((ably.Message message) {
print("message is fired");//it's not working
final data = jsonEncode(message.data);
final response = jsonDecode(data)['message'] as Map<String, dynamic>;
setState(() {
mapData.insert(0, {"message": "From ably", "is_sender": false});
});
});
});
@override
initState(){
super.initState();
subscribeAbly()
}
I'm using Flutter 2.8 and ably_flutter 1.2.15 Any assistance would be much appreciated.