90 lines
3.2 KiB
Dart
90 lines
3.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/presentation/chat/chat_state.dart';
|
|
import 'package:trainhub_flutter/presentation/chat/widgets/thinking_block.dart';
|
|
import 'package:trainhub_flutter/presentation/chat/widgets/typing_indicator.dart';
|
|
|
|
class TypingBubble extends StatelessWidget {
|
|
const TypingBubble({
|
|
super.key,
|
|
required this.thinkingSteps,
|
|
this.streamingContent,
|
|
});
|
|
|
|
final List<ThinkingStep> thinkingSteps;
|
|
final String? streamingContent;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final maxWidth = MediaQuery.of(context).size.width * 0.55;
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: UIConstants.spacing12),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: 28,
|
|
height: 28,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceContainerHigh,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: const Icon(
|
|
Icons.auto_awesome_rounded,
|
|
size: 14,
|
|
color: AppColors.accent,
|
|
),
|
|
),
|
|
const SizedBox(width: UIConstants.spacing8),
|
|
Flexible(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (thinkingSteps.isNotEmpty)
|
|
Container(
|
|
constraints: BoxConstraints(maxWidth: maxWidth),
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
child: ThinkingBlock(steps: thinkingSteps),
|
|
),
|
|
if (streamingContent != null && streamingContent!.isNotEmpty)
|
|
Container(
|
|
constraints: BoxConstraints(maxWidth: maxWidth),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: UIConstants.spacing16,
|
|
vertical: UIConstants.spacing12,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceContainer,
|
|
borderRadius: const BorderRadius.only(
|
|
topLeft: Radius.circular(16),
|
|
topRight: Radius.circular(16),
|
|
bottomLeft: Radius.circular(4),
|
|
bottomRight: Radius.circular(16),
|
|
),
|
|
border:
|
|
Border.all(color: AppColors.border, width: 1),
|
|
),
|
|
child: MarkdownBody(
|
|
data: streamingContent!,
|
|
styleSheet: MarkdownStyleSheet(
|
|
p: const TextStyle(
|
|
color: AppColors.textPrimary,
|
|
fontSize: 14,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
),
|
|
)
|
|
else
|
|
const TypingIndicator(),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|