anoop4real / Flutter_MQTT

An attempt with Flutter
59 stars 33 forks source link

If multiple subscriptions are required, updates. Listen should be set in mqttManager or separately on each page #5

Open jahnli opened 3 years ago

jahnli commented 3 years ago

If multiple subscriptions are required, updates. Listen should be set in mqttManager or separately on each page

anoop4real commented 3 years ago

@jahnli Check here https://github.com/anoop4real/Flutter_mqtt_new this uses a shared manager.

jahnli commented 3 years ago

The current situation is that I subscribed to one topic on page A and wrote an MqttClientTopicFilter updates. Listen. When I destroyed page A, I cancelled the subscription and re-subscribed to the topic when I entered page A again ,This resulted in repeated messages being returned multiple times in update.listen

jahnli commented 3 years ago

If multiple pages have multiple topics, updates. Listen needs to be written several times

anoop4real commented 3 years ago

@jahnli Please check here https://github.com/anoop4real/Flutter_mqtt_new this issue is fixed https://github.com/anoop4real/Flutter_mqtt_new/issues/1

Also if you have multiple topics subscribed, just filter those by topic from payload, hope it helps

jahnli commented 3 years ago

I met the same problem, but I didn't find the specific code to solve this problem. Could you please intercept or tell me which one it is

anoop4real commented 3 years ago

@jahnli Mostly it was because the usecase in this project was basic, the main issue was that I was not handling the subcribe call properly. The idea is make sure the mqttClient listen only once and subscription can happen multiple times

jahnli commented 3 years ago

Ok, thanks for your advice