122 lines
4.2 KiB
Dart
122 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
import 'package:trainhub_flutter/core/constants/ui_constants.dart';
|
|
import 'package:trainhub_flutter/core/theme/app_colors.dart';
|
|
import 'package:trainhub_flutter/domain/entities/chat_message.dart';
|
|
|
|
class MessageBubble extends StatelessWidget {
|
|
const MessageBubble({
|
|
super.key,
|
|
required this.message,
|
|
required this.formattedTime,
|
|
});
|
|
|
|
final ChatMessageEntity message;
|
|
final String formattedTime;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isUser = message.isUser;
|
|
final maxWidth = MediaQuery.of(context).size.width * 0.55;
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: UIConstants.spacing12),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
isUser ? MainAxisAlignment.end : MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (!isUser) ...[
|
|
_buildAvatar(
|
|
Icons.auto_awesome_rounded,
|
|
AppColors.surfaceContainerHigh,
|
|
),
|
|
const SizedBox(width: UIConstants.spacing8),
|
|
],
|
|
Flexible(
|
|
child: Column(
|
|
crossAxisAlignment:
|
|
isUser ? CrossAxisAlignment.end : CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
constraints: BoxConstraints(maxWidth: maxWidth),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: UIConstants.spacing16,
|
|
vertical: UIConstants.spacing12,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: isUser
|
|
? AppColors.zinc700
|
|
: AppColors.surfaceContainer,
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: const Radius.circular(16),
|
|
topRight: const Radius.circular(16),
|
|
bottomLeft: isUser
|
|
? const Radius.circular(16)
|
|
: const Radius.circular(4),
|
|
bottomRight: isUser
|
|
? const Radius.circular(4)
|
|
: const Radius.circular(16),
|
|
),
|
|
border: isUser
|
|
? null
|
|
: Border.all(color: AppColors.border, width: 1),
|
|
),
|
|
child: isUser
|
|
? SelectableText(
|
|
message.content,
|
|
style: const TextStyle(
|
|
color: AppColors.textPrimary,
|
|
fontSize: 14,
|
|
height: 1.5,
|
|
),
|
|
)
|
|
: MarkdownBody(
|
|
data: message.content,
|
|
styleSheet: MarkdownStyleSheet(
|
|
p: const TextStyle(
|
|
color: AppColors.textPrimary,
|
|
fontSize: 14,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
child: Text(
|
|
formattedTime,
|
|
style: const TextStyle(
|
|
color: AppColors.textMuted,
|
|
fontSize: 11,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (isUser) ...[
|
|
const SizedBox(width: UIConstants.spacing8),
|
|
_buildAvatar(
|
|
Icons.person_rounded,
|
|
AppColors.accent.withValues(alpha: 0.15),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAvatar(IconData icon, Color backgroundColor) {
|
|
return Container(
|
|
width: 28,
|
|
height: 28,
|
|
decoration: BoxDecoration(
|
|
color: backgroundColor,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(icon, size: 14, color: AppColors.accent),
|
|
);
|
|
}
|
|
}
|