Closed yuefeng007 closed 4 years ago
Which version of the client are you using? I'll need a full client log to see whats happening.
您正在使用哪个版本的客户端?我需要完整的客户端日志以查看发生了什么。
client : android mqtt_client: ^6.0.0
demo code:
final MqttClient client = MqttClient('test.mosquitto.org', ''); client.onDisconnected = () { print('MQTT-->disconnected');}; client.onConnected = () {print('MQTT-->connecting');}; client.onSubscribed = (String topic) {print('MQTT-->onSubscribed ');} client.pongCallback = () { print('MQTT-->pong');}; await client.connect();
log:
MQTT-->connecting E/flutter (18435): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The setter 'onDisconnected=' was called on null. E/flutter (18435): Receiver: null E/flutter (18435): Tried calling: onDisconnected=Closure: () => void from Function 'internalDisconnect':. E/flutter (18435): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter (18435): #1 MqttClient.connect (package:mqtt_client/src/mqtt_client.dart:185:23) E/flutter (18435): #2 MqttManager.connect (package:appl/config/Mqtt.dart:55:25) E/flutter (18435): #3 new MqttManager._internal (package:appl/config/Mqtt.dart:39:5) E/flutter (18435): #4 MqttManager._getInstance (package:appl/config/Mqtt.dart:44:23) E/flutter (18435): #5 new MqttManager (package:appl/config/Mqtt.dart:12:28) E/flutter (18435): #6 _NoticePageState.build.<anonymous closure> (package:appl/modules/notice/notice_page.dart:77:21) E/flutter (18435): #7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14) E/flutter (18435): #8 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36) E/flutter (18435): #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter (18435): #10 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11) E/flutter (18435): #11 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5) E/flutter (18435): #12 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7) E/flutter (18435): #13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9) E/flutter (18435): #14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12) E/flutter (18435): #15 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9) E/flutter (18435): #16 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8) E/flutter (18435): #17 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18) E/flutter (18435): #18 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7) E/flutter (18435): #19 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19) E/flutter (18435): #20 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter (18435): #21 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) E/flutter (18435): #22 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) E/flutter (18435): #23 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) E/flutter (18435): #24 _rootRunUnary (dart:async/zone.dart:1138:13) E/flutter (18435): #25 _CustomZone.runUnary (dart:async/zone.dart:1031:19) E/flutter (18435): #26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7) E/flutter (18435): #27 _invoke1 (dart:ui/hooks.dart:273:10) E/flutter (18435): #28 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
From version 6.0.0 of the client you can't use MqttClient you must use the client appropriate for your platform, in your case use MqttServerClient, please read the changelog.
Thank you very much.
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The setter 'onDisconnected=' was called on null. E/flutter ( 5787): Receiver: null E/flutter ( 5787): Tried calling: onDisconnected=Closure: () => void from Function 'internalDisconnect':.