shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

Flutter client just dose not work. #57

Closed uwejan closed 5 years ago

uwejan commented 5 years ago

Hello there, I just download the repo to test the flutter example, it just dose not seem to work, many error my ide detected, Undefined class mqtt.ConnectionState, Too many positional arguments every where, can not even get it start to debug. Off course enabled dart '2', and got all dependencies. Thank you.

shamblett commented 5 years ago

The flutter example was originally written with an older version of the client, as you have discovered it will need updating to use the latest client(5.1). I don't use flutter so its difficult for me to do this, you should just be able to fix all the errors/warnings and be good to go, ConnectionState is now MqttConnectionState for instance, the analyzer should tell you all this.

You definitely need Dart 2.0

uwejan commented 5 years ago

Hey @shamblett , almost there, what about this one, says 4 provided 3 expected

void _sendMessage() {
    final mqtt.MqttClientPayloadBuilder builder =
        mqtt.MqttClientPayloadBuilder();

    builder.addString(_messageContent);
    widget.client.publishMessage(
      _topicContent,
      mqtt.MqttQos.values[_qosValue],
      builder.payload,
      _retainValue,
    );
    Navigator.pop(context);
  }
shamblett commented 5 years ago

Try 'retain:_retainValue' as per the API for the publishMessage method

uwejan commented 5 years ago

Hi, using the example from pub website, i wish to run the method on main file of my flutter, and have the result of incoming notifications accessed from other classes, how can i do that please.

  client.updates.listen((List<MqttReceivedMessage<MqttMessage>> c) {
    final MqttPublishMessage recMess = c[0].payload;
    final String pt =
        MqttPublishPayload.bytesToStringAsString(recMess.payload.message);

    /// The above may seem a little convoluted for users only interested in the
    /// payload, some users however may be interested in the received publish message,
    /// lets not constrain ourselves yet until the package has been in the wild
    /// for a while.
    /// The payload is a byte buffer, this will be specific to the topic
    print(
        'EXAMPLE::Change notification:: topic is <${c[0].topic}>, payload is <-- $pt -->');
    print('');
  });

i want pt , to be accessed from other classes, so i have only one connection on my main, and want client, to be accessed to so i can pub from other classes, what would be the way to do this please. *edit One more question, is it possible to run the client on background mode, or as service on flutter?