GithubHelp home page GithubHelp logo

hivemq-cloud / mqtt.dart-client-example Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 3.0 169 KB

Complete example project to get started with MQTT.dart on HiveMQ Cloud

License: Apache License 2.0

Dart 100.00%
dart example hivemq hivemq-cloud mqtt mqttdart

mqtt.dart-client-example's People

Contributors

adriansterr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mqtt.dart-client-example's Issues

Using Provider

We are able to Publish a new message ( every 5sec) and able to Subscribe to the message.
We do see the new message update in the terminal from the print(message) from the client.updates.listen() block.

Problem:
We then modified the MQTTClientWrapper with 'extends changeNotifier'

so with client.updates.listen() occurs, we pass the data to a widget using Provider

void _subscribeToTopic(String topicName) {
print('Subscribing to the $topicName topic');
client.subscribe(topicName, MqttQos.atMostOnce);

// print the message when it is received
client.updates.listen((List<MqttReceivedMessage<MqttMessage>> c) {
  final MqttPublishMessage recMess = c[0].payload;
  var message = MqttPublishPayload.bytesToStringAsString(recMess.payload.message);

  print('YOU GOT A NEW MESSAGE:');
  print(message);  // Displays message correctly

  myData = message;
  notifyListeners();

});

In the top level widget, we pass the Provider down to the Text() widget , but the update never seem to occur.

Text(Provider.of(context,listen: true).myData , // This is not receiving the changeNotifier 'myData'
style: TextStyle(fontSize: 10,color: Colors.white),),

}

Any insight on why the notifyListeners inside the client.updates.listen() is not functions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.