From 3f43ecb8c102fbd14812f0e79095a1df136096ab Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Tue, 6 Jan 2026 17:11:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(call):=20=E4=BF=AE=E5=A4=8D=E9=80=9A?= =?UTF-8?q?=E8=AF=9D=E5=8A=9F=E8=83=BD=E4=B8=AD=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=92=8C=E4=BB=B7=E6=A0=BC=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在送礼失败时重置 isCreatingChannel 状态避免状态不一致 - 修复创建RTC频道失败时的返回值处理,添加 channelData 为 null 的检查 - 修复通话频道创建成功时的空指针访问问题 - 延迟1秒调用 _consumeOneOnOneRtcChannel 方法确保会话正确建立 - 修复免费产品价格显示为空字符串的格式化逻辑 - 优化通话类型选择对话框的价格显示,免费产品不显示价格信息 --- lib/controller/message/call_controller.dart | 16 +++++++++++----- .../message/call_type_selection_dialog.dart | 11 +++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/controller/message/call_controller.dart b/lib/controller/message/call_controller.dart index da44f39..291bbea 100644 --- a/lib/controller/message/call_controller.dart +++ b/lib/controller/message/call_controller.dart @@ -168,6 +168,7 @@ class CallController extends GetxController { if (!response.data.data!.success && response.data.data!.code == 'E0002') { // 玫瑰不足,显示 toast 并弹出充值弹框 SmartDialog.showToast('玫瑰不足请充值'); + isCreatingChannel.value = false; Get.log('❌ 送礼失败: ${response.data.data}'); // 使用 addPostFrameCallback 确保在下一帧显示弹框,避免与 toast 冲突 WidgetsBinding.instance.addPostFrameCallback((_) { @@ -259,15 +260,17 @@ class CallController extends GetxController { type: type, toUserId: targetUserId, ); - _callUid = channelData?.uid; - _callChannelId = channelData?.channelId; - if (channelData == null) { + if (channelData == null) { + return false; + } + if (!channelData.success) { print('❌ [CallController] 创建RTC频道失败,无法发起通话'); SmartDialog.showToast('创建通话频道失败'); return false; } - - print('✅ [CallController] RTC频道创建成功: ${channelData.channelId}'); + _callUid = channelData?.uid; + _callChannelId = channelData?.channelId; + print('✅ [CallController] RTC频道创建成功: ${channelData!.channelId}'); // 创建通话会话 final session = CallSession( @@ -447,6 +450,9 @@ class CallController extends GetxController { // 接收方接听后,立即调用一次消费接口并启动定时器 // 确保 _callChannelId 已设置 if (_callChannelId != null && _callChannelId!.isNotEmpty) { + Future .delayed(Duration(seconds: 1), () async { + await _consumeOneOnOneRtcChannel(); + }); _startConsumeTimer(); print('✅ [CallController] 接收方接听后已启动消费定时器'); } diff --git a/lib/widget/message/call_type_selection_dialog.dart b/lib/widget/message/call_type_selection_dialog.dart index 21658d4..96072fe 100644 --- a/lib/widget/message/call_type_selection_dialog.dart +++ b/lib/widget/message/call_type_selection_dialog.dart @@ -38,11 +38,18 @@ class CallTypeSelectionDialog extends StatelessWidget { /// 格式化价格显示 String _formatPrice(ChatAudioProductModel? product) { if (product == null) return '35玫瑰/分钟'; + + // 如果是免费产品,不显示分钟 + if (product.isFreeProduct) { + return ''; + } + return '${product.unitSellingPrice.toInt()}玫瑰/分钟'; } @override Widget build(BuildContext context) { + String price = _formatPrice(voiceProduct); return Container( decoration: BoxDecoration( color: Colors.white, @@ -65,7 +72,7 @@ class CallTypeSelectionDialog extends StatelessWidget { padding: EdgeInsets.symmetric(vertical: 16.w), child: Center( child: Text( - '语音通话 (${_formatPrice(voiceProduct)})', + price.isNotEmpty ? '语音通话 ($price)' : '语音通话', style: TextStyle( fontSize: 16.sp, color: const Color.fromRGBO(51, 51, 51, 1), @@ -91,7 +98,7 @@ class CallTypeSelectionDialog extends StatelessWidget { padding: EdgeInsets.symmetric(vertical: 16.w), child: Center( child: Text( - '视频通话 (${_formatPrice(videoProduct)})', + price.isNotEmpty ? '视频通话 ($price)' : '视频通话', style: TextStyle( fontSize: 16.sp, color: const Color.fromRGBO(51, 51, 51, 1),