You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.8 KiB
94 lines
2.8 KiB
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.isLoading)
|
|
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<Color>(
|
|
isUser ? Colors.white : AppColors.primary,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Text(
|
|
'思考中...',
|
|
style: TextStyle(
|
|
color: isUser ? Colors.white : Colors.black,
|
|
fontSize: 12.sp,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|