Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 7, 2021

Conversation

stijn1989
Copy link
Contributor

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();
  }
)
....

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.
@shamblett shamblett merged commit 7d80ba0 into shamblett:master Oct 7, 2021
@shamblett
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants