import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import '../../modules/chat/models/message_model.dart'; import '../theme/app_colors.dart'; class MessageBubble extends StatelessWidget { final Message message; final bool isUser; final String? userAvatar; final String? agentAvatar; const MessageBubble({ Key? key, required this.message, required this.isUser, this.userAvatar, this.agentAvatar, }) : super(key: key); @override Widget build(BuildContext context) { return Padding( padding: EdgeInsets.only(bottom: 16.h), child: Row( mainAxisAlignment: isUser ? MainAxisAlignment.end : MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Flexible( child: Container( padding: EdgeInsets.all(12.r), decoration: BoxDecoration( color: isUser ? AppColors.primary : Colors.grey[200], borderRadius: BorderRadius.circular(16.r), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // 消息内容 if (message.content.isNotEmpty) SelectableText( message.content, style: TextStyle( color: isUser ? Colors.white : Colors.black, fontSize: 16.sp, height: 1.5, letterSpacing: 0.2, ), textAlign: TextAlign.left, maxLines: null, enableInteractiveSelection: true, textWidthBasis: TextWidthBasis.longestLine, ), // 加载指示器 if (message.isIntermediate) Padding( padding: EdgeInsets.only(top: message.content.isNotEmpty ? 8.h : 0), child: _buildLoadingIndicator(), ), ], ), ), ), ], ), ); } Widget _buildLoadingIndicator() { return Row( mainAxisSize: MainAxisSize.min, children: [ SizedBox( width: 12.w, height: 12.h, child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation( isUser ? Colors.white : AppColors.primary, ), ), ), SizedBox(width: 8.w), Text( '思考中...', style: TextStyle( color: isUser ? Colors.white : Colors.black, fontSize: 12.sp, ), ), ], ); } }