shamblett / mqtt5_client

A server and browser based MQTT 5 client for dart
Other
51 stars 29 forks source link

mqtt_client.dart: "Null check operator used on a null value" for authenticationManager in connect() method. #15

Closed stijn1989 closed 3 years ago

stijn1989 commented 3 years ago

When an active connection to the MQTT server is lost. The _disconnect() method sets the authenticationManager to null. When you call connect() again on the client, you get an exception "Null check operator used on a null value". With this extra line of code, the authenticationManager has an object for sure.

Class MQTT {
  ....

  Future<MqttConnectionStatus?> connect() async {
    return client.connect(user, pass);
  }

  ...
}
...
FloatingActionButton(
  child: Icon(Icons.message),
  onPressed: () async {
      await mqtt.connect(); //<- here you get the exception when pressing the button when the MQTT is back online.
      mqtt.sub();
  }
)
....
shamblett commented 3 years ago

Yes good catch, client updated and re published at version 3.1.1