buildAppendBubble method
使用父类提供的扩展点,在主气泡下方追加“语音转文字”气泡 仅显示文字与边框:当该消息处于可见列表且已有转写文本时展示
Implementation
@override
Widget? buildAppendBubble(BuildContext context) {
final RCIMIWVoiceMessage voiceMessage = message as RCIMIWVoiceMessage;
final int? id = voiceMessage.messageId;
final chatProvider = context.read<RCKChatProvider>();
final bool isVisible =
chatProvider.speechToTextMessageIdsVisible.contains(id);
final String text = voiceMessage.speechToTextInfo?.text ?? '';
final bool isConverting = voiceMessage.speechToTextInfo?.status ==
RCIMIWSpeechToTextStatus.converting;
final bool isFailed = voiceMessage.speechToTextInfo?.status ==
RCIMIWSpeechToTextStatus.failed &&
isVisible;
if (isFailed) {
return Container(
margin: const EdgeInsets.only(top: 6.0),
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(
color: RCKThemeProvider().themeColor.textAuxiliary ?? Colors.grey,
width: 0.5),
borderRadius: BorderRadius.circular(6),
color: RCKThemeProvider().themeColor.bgAuxiliary1 ?? Colors.grey,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
ImageUtil.getImageWidget(
RCKThemeProvider().themeIcon.attention ?? '',
width: 14,
height: 14,
color: RCKThemeProvider().themeColor.textAuxiliary),
const SizedBox(width: 5),
Text(
"语音转换失败",
style: TextStyle(
color: RCKThemeProvider().themeColor.textAuxiliary ??
Colors.grey,
fontSize: 14,
height: 1.35),
),
],
),
);
}
if (isConverting) {
return _SttConvertingIndicator(
onFirstFrame: () => autoScrollIfLast(context),
);
}
if (id == null) return null;
if (!isVisible) {
return null;
}
final bool isShown =
chatProvider.speechToTextMessageIdsHasShown.contains(id);
final bool isMe = message.direction == RCIMIWMessageDirection.send;
final Alignment alignment =
isMe ? Alignment.centerRight : Alignment.centerLeft;
if (!isShown) {
return _SttAppendBubbleAnimated(
text: text,
borderColor: RCKThemeProvider().themeColor.textAuxiliary ?? Colors.grey,
textColor: RCKThemeProvider().themeColor.textPrimary ?? Colors.black,
bgColor: RCKThemeProvider().themeColor.bgAuxiliary1 ?? Colors.grey,
onShown: () => chatProvider.addSpeechToTextMessageIdHasShown(id),
alignment: alignment,
messageId: id,
);
}
return _SttAppendBubblePlain(
text: text,
borderColor: RCKThemeProvider().themeColor.textAuxiliary ?? Colors.grey,
textColor: RCKThemeProvider().themeColor.textPrimary ?? Colors.black,
bgColor: RCKThemeProvider().themeColor.bgAuxiliary1 ?? Colors.grey,
alignment: alignment,
);
}