feat: unified 1..9 words session narrative, dice input before reveal, dedicated results screen, and clean session history grouping

This commit is contained in:
Alma Alexyz
2026-08-31 15:23:59 +05:00
parent bc892c3388
commit 6f9d4d4cca
11 changed files with 1207 additions and 1099 deletions
+195 -195
View File
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import '../models/history_entry_model.dart';
import '../services/words_repository.dart';
import '../widgets/gradient_star_badge.dart';
import 'session_result_screen.dart';
class HistoryScreen extends StatefulWidget {
const HistoryScreen({super.key});
@@ -26,7 +27,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
],
),
content: const Text(
'Все сохранённые записи гаданий, вопросов и AI-трактовок будут удалены.',
'Все сохранённые сессии гаданий и AI-трактовки будут удалены.',
),
actions: [
TextButton(
@@ -48,21 +49,27 @@ class _HistoryScreenState extends State<HistoryScreen> {
);
}
void _copyEntry(HistoryEntry entry) {
var text =
'✨ Оракул 999 — Запись из Истории ✨\n'
'Время: ${entry.formattedDate}\n'
'${entry.question != null && entry.question!.isNotEmpty ? "Вопрос: «${entry.question}»\n" : ""}'
'Тип: ${entry.readingType}${entry.positionTitle != null ? ' (${entry.positionTitle})' : ''}\n'
'Знак №${entry.formattedSessionNumber}: ${entry.word.toUpperCase()}\n'
'Часть речи: ${entry.partOfSpeech}\n\n'
'🔮 Толкование:\n${entry.symbolicMeaning}';
void _copySession(OracleSession session) {
final buf = StringBuffer();
buf.writeln('✨ Оракул 999 — Запись Сессии ✨');
buf.writeln('Дата: ${session.formattedDate}');
if (session.question != null && session.question!.isNotEmpty) {
buf.writeln('Вопрос: «${session.question}»');
}
buf.writeln('Знаков: ${session.words.length}\n');
if (entry.aiInterpretation != null && entry.aiInterpretation!.isNotEmpty) {
text += '\n\n🤖 AI Трактовка (G4F):\n${entry.aiInterpretation}';
for (int i = 0; i < session.words.length; i++) {
final w = session.words[i];
buf.writeln('🔮 Знак #${w.formattedSessionNumber}: ${w.word.toUpperCase()} (${w.partOfSpeech})');
buf.writeln(' ${w.symbolicMeaning}\n');
}
Clipboard.setData(ClipboardData(text: text));
if (session.aiInterpretation != null && session.aiInterpretation!.isNotEmpty) {
buf.writeln('🤖 AI Трактовка (G4F):');
buf.writeln(session.aiInterpretation);
}
Clipboard.setData(ClipboardData(text: buf.toString()));
HapticFeedback.lightImpact();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
@@ -70,7 +77,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
children: [
GradientStar(size: 18),
SizedBox(width: 10),
Expanded(child: Text('Запись скопирована в буфер обмена')),
Expanded(child: Text('Сессия скопирована в буфер обмена')),
],
),
duration: const Duration(seconds: 2),
@@ -84,7 +91,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
final historyList = _repo.history;
final sessionsList = _repo.sessions;
return Scaffold(
appBar: AppBar(
@@ -93,13 +100,13 @@ class _HistoryScreenState extends State<HistoryScreen> {
GradientStar(size: 24),
SizedBox(width: 10),
Text(
'История гаданий',
'История сессий',
style: TextStyle(fontWeight: FontWeight.w900),
),
],
),
actions: [
if (historyList.isNotEmpty)
if (sessionsList.isNotEmpty)
IconButton(
tooltip: 'Очистить историю',
icon: const Icon(Icons.delete_outline_rounded),
@@ -107,7 +114,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
),
],
),
body: historyList.isEmpty
body: sessionsList.isEmpty
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@@ -115,7 +122,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
const GradientStar(size: 48),
const SizedBox(height: 16),
Text(
'История пока пуста',
'История сессий пока пуста',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
@@ -124,7 +131,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Text(
'Задайте вопрос и бросьте жребий, чтобы получить ответ оракула и сохранить его здесь.',
'Задайте вопрос, совершите броски и откройте знаки, чтобы сохранить сессию здесь.',
textAlign: TextAlign.center,
style: TextStyle(color: theme.colorScheme.outline),
),
@@ -134,207 +141,200 @@ class _HistoryScreenState extends State<HistoryScreen> {
)
: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
itemCount: historyList.length,
separatorBuilder: (_, _) => const SizedBox(height: 10),
itemCount: sessionsList.length,
separatorBuilder: (_, _) => const SizedBox(height: 12),
itemBuilder: (context, index) {
final item = historyList[index];
final session = sessionsList[index];
return Card(
elevation: 3,
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
borderRadius: BorderRadius.circular(20),
side: BorderSide(
color: const Color(0xFFFFD54F).withValues(alpha: 0.2),
color: const Color(0xFFFFD54F).withValues(alpha: 0.25),
),
),
color: isDark ? const Color(0xFF1B1D30) : theme.colorScheme.surface,
child: Padding(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Top header: Timestamp and Reading type
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const Icon(
Icons.access_time_rounded,
size: 14,
color: Color(0xFFFFD54F),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => SessionResultScreen(session: session),
),
).then((_) => setState(() {}));
},
borderRadius: BorderRadius.circular(20),
child: Padding(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Top Header: Date, Words Count, Actions
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const Icon(
Icons.access_time_rounded,
size: 14,
color: Color(0xFFFFD54F),
),
const SizedBox(width: 5),
Text(
session.formattedDate,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Color(0xFFFFD54F),
),
),
],
),
Row(
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: const Color(0xFF2A2D4A),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.3),
),
),
child: Text(
'${session.words.length} ${session.words.length == 1 ? "знак" : (session.words.length < 5 ? "знака" : "знаков")}',
style: const TextStyle(
fontSize: 11,
color: Color(0xFFFFF9C4),
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 4),
IconButton(
icon: const Icon(Icons.copy_rounded, size: 16),
tooltip: 'Скопировать',
onPressed: () => _copySession(session),
),
IconButton(
icon: const Icon(Icons.delete_outline, size: 16),
tooltip: 'Удалить',
onPressed: () async {
await _repo.deleteSession(session.id);
setState(() {});
},
),
],
),
],
),
// Question Box if present
if (session.question != null && session.question!.isNotEmpty) ...[
const SizedBox(height: 8),
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: const Color(0xFF22243C),
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
const Icon(Icons.help_outline_rounded, size: 14, color: Color(0xFFFFD54F)),
const SizedBox(width: 6),
Expanded(
child: Text(
'Вопрос: «${session.question}»',
style: const TextStyle(
fontSize: 12.5,
fontStyle: FontStyle.italic,
color: Color(0xFFFFF9C4),
),
),
),
],
),
),
],
const SizedBox(height: 10),
// Words Chips Row
Wrap(
spacing: 6,
runSpacing: 6,
children: session.words.map((w) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF131524) : theme.colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.3),
),
),
const SizedBox(width: 5),
Text(
item.formattedDate,
child: Text(
'#${w.formattedSessionNumber} ${w.word.toUpperCase()}',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12,
fontWeight: FontWeight.w600,
color: Color(0xFFFFD54F),
),
),
],
),
);
}).toList(),
),
// AI Interpretation Snippet if generated
if (session.aiInterpretation != null && session.aiInterpretation!.isNotEmpty) ...[
const SizedBox(height: 10),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
width: double.infinity,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: const Color(0xFF2A2D4A),
borderRadius: BorderRadius.circular(8),
),
child: Text(
item.readingType,
style: const TextStyle(
fontSize: 11,
color: Color(0xFFFFF9C4),
fontWeight: FontWeight.w600,
color: const Color(0xFF261D3A),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: const Color(0xFFBA68C8).withValues(alpha: 0.4),
),
),
),
],
),
// Question snippet if present
if (item.question != null && item.question!.isNotEmpty) ...[
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: const Color(0xFF22243C),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const Icon(Icons.help_outline_rounded, size: 14, color: Color(0xFFFFD54F)),
const SizedBox(width: 6),
Expanded(
child: Text(
'Вопрос: «${item.question}»',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
children: [
Icon(Icons.psychology_rounded, size: 14, color: Color(0xFFE1BEE7)),
SizedBox(width: 6),
Text(
'AI Трактовка (G4F)',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: Color(0xFFE1BEE7),
),
),
],
),
const SizedBox(height: 4),
Text(
session.aiInterpretation!,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 12,
fontStyle: FontStyle.italic,
color: Color(0xFFFFF9C4),
height: 1.4,
color: Color(0xFFF3E5F5),
),
),
),
],
),
),
],
if (item.positionTitle != null) ...[
const SizedBox(height: 6),
Text(
item.positionTitle!,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
),
],
const SizedBox(height: 10),
// Word row with number badge
Row(
children: [
GradientStarBadge(
text: '#${item.formattedSessionNumber}',
size: 14,
),
const SizedBox(width: 10),
Expanded(
child: Text(
item.word.toUpperCase(),
style: const TextStyle(
fontWeight: FontWeight.w900,
fontSize: 18,
letterSpacing: 0.8,
),
],
),
),
IconButton(
icon: const Icon(Icons.copy_rounded, size: 18),
tooltip: 'Скопировать',
onPressed: () => _copyEntry(item),
),
IconButton(
icon: const Icon(Icons.delete_outline, size: 18),
tooltip: 'Удалить',
onPressed: () async {
await _repo.deleteHistoryEntry(item.id);
setState(() {});
},
),
],
),
const SizedBox(height: 8),
// Base Meaning snippet
Container(
width: double.infinity,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: isDark
? const Color(0xFF131524)
: theme.colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(12),
),
child: Text(
item.symbolicMeaning,
style: TextStyle(
fontSize: 13,
height: 1.4,
color: isDark ? const Color(0xFFD4D6E6) : Colors.black87,
),
),
),
// AI Interpretation snippet if present
if (item.aiInterpretation != null && item.aiInterpretation!.isNotEmpty) ...[
const SizedBox(height: 8),
Container(
width: double.infinity,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: const Color(0xFF261D3A),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: const Color(0xFFBA68C8).withValues(alpha: 0.4),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
children: [
Icon(Icons.psychology_rounded, size: 14, color: Color(0xFFE1BEE7)),
SizedBox(width: 6),
Text(
'AI Трактовка (G4F)',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: Color(0xFFE1BEE7),
),
),
],
),
const SizedBox(height: 6),
Text(
item.aiInterpretation!,
style: const TextStyle(
fontSize: 12.5,
height: 1.45,
color: Color(0xFFF3E5F5),
),
),
],
),
),
],
],
),
),
),
);