Browse Source

fix(call): 修复通话功能中的错误处理和价格显示问题

- 在送礼失败时重置 isCreatingChannel 状态避免状态不一致
- 修复创建RTC频道失败时的返回值处理,添加 channelData 为 null 的检查
- 修复通话频道创建成功时的空指针访问问题
- 延迟1秒调用 _consumeOneOnOneRtcChannel 方法确保会话正确建立
- 修复免费产品价格显示为空字符串的格式化逻辑
- 优化通话类型选择对话框的价格显示,免费产品不显示价格信息
master
Jolie 2 months ago
parent
commit
3f43ecb8c1
2 changed files with 20 additions and 7 deletions
  1. 16
      lib/controller/message/call_controller.dart
  2. 11
      lib/widget/message/call_type_selection_dialog.dart

16
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] 接收方接听后已启动消费定时器');
}

11
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),

Loading…
Cancel
Save