anoop4real / flutter_mqtt Goto Github PK
View Code? Open in Web Editor NEWAn attempt with Flutter
An attempt with Flutter
If multiple subscriptions are required, updates. Listen should be set in mqttManager or separately on each page
Hello, im trying you app, but when i try to connect in a second mobile, the first automatically disconnect, can you tell me what is wrong?
how can we connect rabbitmq with this package?
Hi,
I'm working on a similar MQTT based flutter project and I had to use streams for rebuilding my widgets upon message arrival. Why is it not essential here?
My Stream is not working tho, I'm using a stream controller to sink payload right after the the variable 'pt' is created and assigned a value. I'm listening to it with StreamBuilder Widget on main.dart and rebuilding a card based on it.
The issue is: the card does not rebuild upon message arrival. I can see the message print on the console(using Print) but the listener/subsriber doesn't seem to be working well.
Code:
class PayloadGiver {
final mqttStream = StreamController<String>();
void payloadGiver(String subscribeTopic) {
if (mqttInitComplete == true) {
print('Subscribing to $subscribeTopic');
// Not a wildcard topic
// client.subscribe(subscribeTopic2, MqttQos.atMostOnce);
client.subscribe(subscribeTopic, MqttQos.atMostOnce);
client.updates.listen((List<MqttReceivedMessage<MqttMessage>> c) {
final MqttPublishMessage recMess = c[0].payload;
final pt =
MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
print('The payload is : $pt');
mqttStream.sink.add(pt);
});
}
}
Listener:
StreamBuilder<String>(
stream: mqttStream,
builder: (context, snapshot) {
// if (!snapshot.hasData) return Text('No Data');
// if (snapshot.connectionState == ConnectionState.waiting)
// print("Still Waiting for Data");
// print('Currently, I have: ' + snapshot.data);
if (snapshot.data == 'true')
return SwitchCardOn();
else if (snapshot.data == 'false') {
print(
"I recieved false but did not build the widget");
return SwitchCardOff();
} else
return Text('Waiting');
}),
Please help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.