This commit is contained in:
180
lib/presentation/chat/widgets/thinking_block.dart
Normal file
180
lib/presentation/chat/widgets/thinking_block.dart
Normal file
@@ -0,0 +1,180 @@
|
||||
import 'package:flutter/material.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';
|
||||
|
||||
class ThinkingBlock extends StatefulWidget {
|
||||
const ThinkingBlock({super.key, required this.steps});
|
||||
|
||||
final List<ThinkingStep> steps;
|
||||
|
||||
@override
|
||||
State<ThinkingBlock> createState() => _ThinkingBlockState();
|
||||
}
|
||||
|
||||
class _ThinkingBlockState extends State<ThinkingBlock> {
|
||||
bool _isExpanded = true;
|
||||
|
||||
Color _getStatusColor(ThinkingStepStatus status) {
|
||||
switch (status) {
|
||||
case ThinkingStepStatus.running:
|
||||
return AppColors.info;
|
||||
case ThinkingStepStatus.completed:
|
||||
return AppColors.success;
|
||||
case ThinkingStepStatus.error:
|
||||
return AppColors.destructive;
|
||||
case ThinkingStepStatus.pending:
|
||||
return AppColors.textMuted;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildStatusIcon(ThinkingStepStatus status) {
|
||||
if (status == ThinkingStepStatus.running) {
|
||||
return const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: AppColors.info,
|
||||
),
|
||||
);
|
||||
}
|
||||
final IconData icon;
|
||||
switch (status) {
|
||||
case ThinkingStepStatus.completed:
|
||||
icon = Icons.check_circle_rounded;
|
||||
case ThinkingStepStatus.error:
|
||||
icon = Icons.error_outline_rounded;
|
||||
default:
|
||||
icon = Icons.circle_outlined;
|
||||
}
|
||||
return Icon(icon, size: 14, color: _getStatusColor(status));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(UIConstants.smallBorderRadius),
|
||||
border: Border.all(color: AppColors.border, width: 1),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius:
|
||||
BorderRadius.circular(UIConstants.smallBorderRadius),
|
||||
onTap: () => setState(() => _isExpanded = !_isExpanded),
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.settings_suggest_rounded,
|
||||
size: 16,
|
||||
color: AppColors.warning,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'Assistant actions',
|
||||
style: TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'(${widget.steps.length} steps)',
|
||||
style: const TextStyle(
|
||||
color: AppColors.textMuted,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
_isExpanded
|
||||
? Icons.keyboard_arrow_up
|
||||
: Icons.keyboard_arrow_down,
|
||||
size: 16,
|
||||
color: AppColors.textMuted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_isExpanded)
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(color: AppColors.border, width: 1),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: widget.steps.map(_buildStepRow).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStepRow(ThinkingStep step) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: _buildStatusIcon(step.status),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
step.title,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
if (step.details != null && step.details!.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border:
|
||||
Border.all(color: AppColors.border, width: 1),
|
||||
),
|
||||
child: Text(
|
||||
step.details!,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
color: AppColors.textSecondary,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user