I have just detected the problem when I try to connect to my mosquitto broker. It took a long waste time from me to debug. I have to change to previously version 5.6.3 and it worked fine.
The result when use 5.6.3 version
I/flutter (19396): Start connecting to mqtt broker... I/flutter (19396): mqtt disconnected I/flutter (19396): mqtt connected I/flutter (19396): mqtt connect successful
And the 6.0.0
I/flutter (19396): Start connecting to mqtt broker... I/flutter (19396): NoSuchMethodError: The setter 'onDisconnected=' was called on null. I/flutter (19396): Receiver: null I/flutter (19396): Tried calling: onDisconnected=Closure: () => void from Function 'internalDisconnect':. I/flutter (19396): mqtt disconnected I/flutter (19396): mqtt disconnected
I have just detected the problem when I try to connect to my mosquitto broker. It took a long waste time from me to debug. I have to change to previously version 5.6.3 and it worked fine.
`Future mqttSetup(String ip, int port, String username, String password) async {
client = mqtt.MqttClient(ip, '');
client.port = port;
client.logging(on: false);
client.keepAlivePeriod = 30;
client.onConnected = _onConnect;
client.onDisconnected = _onDisconnect;
final mqtt.MqttConnectMessage connMess = mqtt.MqttConnectMessage()
.withClientIdentifier("Mobile android 1")
.startClean()
.keepAliveFor(30);
client.connectionMessage = connMess;
try {
print("Start connecting to mqtt broker...");
await client.connect(username, password);
} catch (e) {
print(e);
client.disconnect();
}
}
_onConnect() { print("mqtt connected"); }
_onDisconnect(){ print("mqtt disconnected"); }`
The result when use 5.6.3 version
I/flutter (19396): Start connecting to mqtt broker... I/flutter (19396): mqtt disconnected I/flutter (19396): mqtt connected I/flutter (19396): mqtt connect successful
And the 6.0.0
I/flutter (19396): Start connecting to mqtt broker... I/flutter (19396): NoSuchMethodError: The setter 'onDisconnected=' was called on null. I/flutter (19396): Receiver: null I/flutter (19396): Tried calling: onDisconnected=Closure: () => void from Function 'internalDisconnect':. I/flutter (19396): mqtt disconnected I/flutter (19396): mqtt disconnected