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.
...
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.