我在使用来自 TDLib 的 Flutter 端口的 SendMessage 函数时遇到问题,该函数可在此处找到:https://pub.dev/packages/tdlib。虽然我以类似的方式从该插件执行其他功能,但它们工作得很好,我不完全明白是什么导致了这个问题。这是我的函数使用示例:
sendMessage() async {
TdApi.FormattedText messageText = TdApi.FormattedText(text: messageGetter.text,);
TdApi.MessageSendOptions messageSendOptions = TdApi.MessageSendOptions(disableNotification: false) ;
TdApi.InputMessageText message = TdApi.InputMessageText(text: messageText);
final result = await context.read<TelegramService>().send(
TdApi.SendMessage(chatId: contact_id, inputMessageContent: message, options: messageSendOptions),
);
print(result);
}
来自 Android Studio 的堆栈跟踪:
E/flutter (13086): #0 _JsonStringifier.writeObject (dart:convert/json.dart:688:7)
E/flutter (13086): #1 _JsonStringStringifier.printOn (dart:convert/json.dart:877:17)
E/flutter (13086): #2 _JsonStringStringifier.stringify (dart:convert/json.dart:862:5)
E/flutter (13086): #3 JsonEncoder.convert (dart:convert/json.dart:262:30)
E/flutter (13086): #4 JsonCodec.encode (dart:convert/json.dart:172:45)
E/flutter (13086): #5 TdClient.clientSend (package:tdlib/src/tdclient/tdclient.dart:32:63)
E/flutter (13086): #6 TelegramService.send (package:fima/services/telegram_service.dart:195:22)
E/flutter (13086): #7 _ChatScreenState.sendMessage (package:fima/screens/main/chat.dart:210:58)
E/flutter (13086): #8 _ChatScreenState.build.<anonymous closure>.<anonymous closure> (package:fima/screens/main/chat.dart:94:50)
E/flutter (13086): #9 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
E/flutter (13086): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (13086): #11 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:607:11)
E/flutter (13086): #12 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
E/flutter (13086): #13 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:230:7)
E/flutter (13086): #14 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
E/flutter (13086): #15 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:93:12)
E/flutter (13086): #16 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:138:9)
E/flutter (13086): #17 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
E/flutter (13086): #18 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:136:18)
E/flutter (13086): #19 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:122:7)
E/flutter (13086): #20 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:439:19)
E/flutter (13086): #21 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
E/flutter (13086): #22 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:287:11)
E/flutter (13086): #23 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
E/flutter (13086): #24 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
E/flutter (13086): #25 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
E/flutter (13086): #26 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
E/flutter (13086): #27 _rootRunUnary (dart:async/zone.dart:1370:13)
E/flutter (13086): #28 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (13086): #29 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (13086): #30 _invoke1 (dart:ui/hooks.dart:182:10)
E/flutter (13086): #31 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:282:7)
E/flutter (13086): #32 _dispatchPointerDataPacket (dart:ui/hooks.dart:96:31)
答案 0 :(得分:0)
对于任何曾经遇到过同样问题的人,我想我已经解决了。 TdApi 中的函数 SendMessage() 要求“options:”参数具有值。这可以通过对象 MessageSendOptions() 来完成。使用此文档作为参考:https://pub.dev/documentation/tdlib/latest/td_api/SendMessage-class.html