feat: initial release of Oracle 999 divination app

This commit is contained in:
Alma Alexyz
2026-08-31 12:35:13 +05:00
commit 28b85061b9
143 changed files with 16073 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+138
View File
@@ -0,0 +1,138 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'screens/catalog_screen.dart';
import 'screens/history_screen.dart';
import 'screens/home_search_screen.dart';
import 'screens/oracle_spread_screen.dart';
import 'services/words_repository.dart';
import 'widgets/gradient_star_badge.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await WordsRepository().init();
runApp(const Words999App());
}
class Words999App extends StatefulWidget {
const Words999App({super.key});
@override
State<Words999App> createState() => _Words999AppState();
}
class _Words999AppState extends State<Words999App> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Оракул 999 Символов',
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.dark, // Default to rich mystical dark mode
darkTheme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
scaffoldBackgroundColor: const Color(0xFF0C0E1A),
colorScheme: const ColorScheme.dark(
primary: Color(0xFFFFD54F), // Celestial Yellow Gold
onPrimary: Color(0xFF1B1D30),
primaryContainer: Color(0xFF2A2D4A),
onPrimaryContainer: Color(0xFFFFF9C4),
secondary: Color(0xFF80DEEA),
surface: Color(0xFF151829),
onSurface: Color(0xFFE8EAF6),
surfaceContainerHigh: Color(0xFF1E2238),
surfaceContainerHighest: Color(0xFF262B44),
outline: Color(0xFF9FA8DA),
outlineVariant: Color(0xFF3949AB),
),
fontFamily: 'Roboto',
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF0C0E1A),
elevation: 0,
scrolledUnderElevation: 3,
centerTitle: false,
titleTextStyle: TextStyle(
color: Color(0xFFFFF9C4),
fontSize: 20,
fontWeight: FontWeight.w900,
letterSpacing: 0.5,
),
),
navigationBarTheme: NavigationBarThemeData(
backgroundColor: const Color(0xFF101322),
indicatorColor: const Color(0xFF2A2D4A),
labelTextStyle: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return const TextStyle(
color: Color(0xFFFFD54F),
fontWeight: FontWeight.bold,
fontSize: 12,
);
}
return const TextStyle(
color: Color(0xFF9FA8DA),
fontSize: 11,
);
}),
),
),
home: const MainNavigationContainer(),
);
}
}
class MainNavigationContainer extends StatefulWidget {
const MainNavigationContainer({super.key});
@override
State<MainNavigationContainer> createState() => _MainNavigationContainerState();
}
class _MainNavigationContainerState extends State<MainNavigationContainer> {
int _currentIndex = 0;
final List<Widget> _screens = const [
HomeSearchScreen(),
OracleSpreadScreen(),
CatalogScreen(),
HistoryScreen(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _screens,
),
bottomNavigationBar: NavigationBar(
selectedIndex: _currentIndex,
onDestinationSelected: (index) {
setState(() => _currentIndex = index);
HapticFeedback.selectionClick();
},
destinations: const [
NavigationDestination(
icon: Icon(Icons.dialpad_outlined),
selectedIcon: GradientStar(size: 22),
label: 'Поиск 000..999',
),
NavigationDestination(
icon: Icon(Icons.auto_awesome_outlined),
selectedIcon: GradientStar(size: 22),
label: 'Расклады',
),
NavigationDestination(
icon: Icon(Icons.menu_book_outlined),
selectedIcon: GradientStar(size: 22),
label: 'Каталог 999',
),
NavigationDestination(
icon: Icon(Icons.history_rounded),
selectedIcon: GradientStar(size: 22),
label: 'История',
),
],
),
);
}
}
+59
View File
@@ -0,0 +1,59 @@
class HistoryEntry {
final String id;
final DateTime timestamp;
final String word;
final int sessionNumber;
final String partOfSpeech;
final String symbolicMeaning;
final String readingType;
final String? positionTitle;
const HistoryEntry({
required this.id,
required this.timestamp,
required this.word,
required this.sessionNumber,
required this.partOfSpeech,
required this.symbolicMeaning,
this.readingType = 'Жребий',
this.positionTitle,
});
String get formattedSessionNumber => sessionNumber.toString().padLeft(3, '0');
String get formattedDate {
final day = timestamp.day.toString().padLeft(2, '0');
final month = timestamp.month.toString().padLeft(2, '0');
final year = timestamp.year.toString();
final hour = timestamp.hour.toString().padLeft(2, '0');
final minute = timestamp.minute.toString().padLeft(2, '0');
final second = timestamp.second.toString().padLeft(2, '0');
return '$day.$month.$year $hour:$minute:$second';
}
Map<String, dynamic> toMap() {
return {
'id': id,
'timestamp': timestamp.toIso8601String(),
'word': word,
'sessionNumber': sessionNumber,
'partOfSpeech': partOfSpeech,
'symbolicMeaning': symbolicMeaning,
'readingType': readingType,
'positionTitle': positionTitle,
};
}
factory HistoryEntry.fromMap(Map<String, dynamic> map) {
return HistoryEntry(
id: map['id'] as String? ?? DateTime.now().millisecondsSinceEpoch.toString(),
timestamp: DateTime.tryParse(map['timestamp'] as String? ?? '') ?? DateTime.now(),
word: map['word'] as String? ?? '',
sessionNumber: map['sessionNumber'] as int? ?? 0,
partOfSpeech: map['partOfSpeech'] as String? ?? '',
symbolicMeaning: map['symbolicMeaning'] as String? ?? '',
readingType: map['readingType'] as String? ?? 'Жребий',
positionTitle: map['positionTitle'] as String?,
);
}
}
+69
View File
@@ -0,0 +1,69 @@
class WordItem {
final int id; // Base index 0..999
final int sessionNumber; // Dynamic randomized session number 0..999
final String word;
final String partOfSpeech;
final double frequency;
final String category;
final String description;
const WordItem({
required this.id,
this.sessionNumber = 0,
required this.word,
required this.partOfSpeech,
required this.frequency,
this.category = '',
this.description = '',
});
WordItem copyWith({
int? id,
int? sessionNumber,
String? word,
String? partOfSpeech,
double? frequency,
String? category,
String? description,
}) {
return WordItem(
id: id ?? this.id,
sessionNumber: sessionNumber ?? this.sessionNumber,
word: word ?? this.word,
partOfSpeech: partOfSpeech ?? this.partOfSpeech,
frequency: frequency ?? this.frequency,
category: category ?? this.category,
description: description ?? this.description,
);
}
String get formattedSessionNumber => sessionNumber.toString().padLeft(3, '0');
String get formattedId => formattedSessionNumber;
Map<String, dynamic> toMap() {
return {
'id': id,
'sessionNumber': sessionNumber,
'word': word,
'partOfSpeech': partOfSpeech,
'frequency': frequency,
'category': category,
'description': description,
};
}
factory WordItem.fromMap(Map<String, dynamic> map) {
return WordItem(
id: map['id'] as int,
sessionNumber: map['sessionNumber'] as int? ?? (map['id'] as int),
word: map['word'] as String,
partOfSpeech: map['partOfSpeech'] as String,
frequency: (map['frequency'] as num).toDouble(),
category: map['category'] as String? ?? '',
description: map['description'] as String? ?? '',
);
}
@override
String toString() => '#$formattedSessionNumber: $word ($partOfSpeech)';
}
+313
View File
@@ -0,0 +1,313 @@
import 'package:flutter/material.dart';
import '../models/word_model.dart';
import '../services/words_repository.dart';
import '../widgets/gradient_star_badge.dart';
import '../widgets/word_card_widget.dart';
class CatalogScreen extends StatefulWidget {
const CatalogScreen({super.key});
@override
State<CatalogScreen> createState() => _CatalogScreenState();
}
class _CatalogScreenState extends State<CatalogScreen> {
final _repo = WordsRepository();
final _searchController = TextEditingController();
String _selectedCategory = 'Все';
String _sortBy = 'id'; // 'id', 'alpha'
List<WordItem> _filteredWords = [];
@override
void initState() {
super.initState();
_applyFilter();
_searchController.addListener(_applyFilter);
}
@override
void dispose() {
_searchController.removeListener(_applyFilter);
_searchController.dispose();
super.dispose();
}
void _applyFilter() {
final query = _searchController.text.trim();
List<WordItem> list;
if (query.isEmpty) {
list = _repo.allWords;
} else {
list = _repo.search(query);
}
if (_selectedCategory != 'Все') {
list = list
.where((w) => w.partOfSpeech == _selectedCategory || w.category == _selectedCategory)
.toList();
}
if (_sortBy == 'alpha') {
list = List.of(list)..sort((a, b) => a.word.compareTo(b.word));
} else {
// By session number
list = List.of(list)..sort((a, b) => a.sessionNumber.compareTo(b.sessionNumber));
}
setState(() {
_filteredWords = list;
});
}
void _showWordDetails(WordItem word) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => StatefulBuilder(
builder: (context, setSheetState) {
return Container(
padding: const EdgeInsets.only(top: 12),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
),
child: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 40,
height: 4,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.outlineVariant,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(height: 12),
WordCardWidget(
word: word,
onNext: () {
final next = _repo.getNextWord(word.sessionNumber);
Navigator.pop(context);
_showWordDetails(next);
},
onPrevious: () {
final prev = _repo.getPreviousWord(word.sessionNumber);
Navigator.pop(context);
_showWordDetails(prev);
},
onRandom: () {
final rnd = _repo.getRandomWord();
Navigator.pop(context);
_showWordDetails(rnd);
},
),
],
),
),
),
);
},
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
final categories = _repo.getPartsOfSpeech();
return Scaffold(
appBar: AppBar(
title: const Row(
children: [
GradientStar(size: 22),
SizedBox(width: 8),
Text(
'Каталог 999 символов',
style: TextStyle(fontWeight: FontWeight.w900),
),
],
),
actions: [
PopupMenuButton<String>(
tooltip: 'Сортировка',
icon: const Icon(Icons.sort_rounded),
initialValue: _sortBy,
onSelected: (val) {
setState(() {
_sortBy = val;
_applyFilter();
});
},
itemBuilder: (context) => [
const PopupMenuItem(
value: 'id',
child: Row(
children: [
Icon(Icons.format_list_numbered, size: 20),
SizedBox(width: 8),
Text('По номеру сессии (#000..#999)'),
],
),
),
const PopupMenuItem(
value: 'alpha',
child: Row(
children: [
Icon(Icons.sort_by_alpha, size: 20),
SizedBox(width: 8),
Text('По алфавиту (А..Я)'),
],
),
),
],
),
],
),
body: Column(
children: [
// Search input
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: 'Поиск по символу, номеру или смыслу...',
prefixIcon: const Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: GradientStar(size: 16),
),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear),
onPressed: () => _searchController.clear(),
)
: null,
filled: true,
fillColor: isDark
? const Color(0xFF1B1D30)
: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.4),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide(
color: const Color(0xFFFFD54F).withValues(alpha: 0.3),
),
),
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
),
),
),
// Categories Filter Chips
SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Row(
children: categories.map((cat) {
final isSelected = _selectedCategory == cat;
return Padding(
padding: const EdgeInsets.only(right: 6),
child: FilterChip(
label: Text(cat),
selected: isSelected,
onSelected: (selected) {
setState(() {
_selectedCategory = cat;
_applyFilter();
});
},
selectedColor: const Color(0xFF2A2D4A),
checkmarkColor: const Color(0xFFFFD54F),
labelStyle: TextStyle(
color: isSelected ? const Color(0xFFFFF9C4) : null,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
),
);
}).toList(),
),
),
// Stats Bar
Padding(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Найдено: ${_filteredWords.length}',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: theme.colorScheme.outline,
),
),
Text(
'Всего знаков: ${_repo.totalWords}',
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.outline,
),
),
],
),
),
const Divider(height: 1),
// Words List
Expanded(
child: _filteredWords.isEmpty
? const Center(
child: Text('Ничего не найдено'),
)
: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
itemCount: _filteredWords.length,
separatorBuilder: (_, _) => const Divider(height: 1, indent: 64),
itemBuilder: (context, index) {
final item = _filteredWords[index];
return ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
leading: GradientStarBadge(
text: '#${item.formattedSessionNumber}',
size: 14,
),
title: Text(
item.word.toUpperCase(),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
letterSpacing: 0.5,
),
),
subtitle: Text(
item.description,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.onSurfaceVariant,
),
),
trailing: const Icon(Icons.chevron_right_rounded, size: 20),
onTap: () => _showWordDetails(item),
);
},
),
),
],
),
);
}
}
+268
View File
@@ -0,0 +1,268 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../models/history_entry_model.dart';
import '../services/words_repository.dart';
import '../widgets/gradient_star_badge.dart';
class HistoryScreen extends StatefulWidget {
const HistoryScreen({super.key});
@override
State<HistoryScreen> createState() => _HistoryScreenState();
}
class _HistoryScreenState extends State<HistoryScreen> {
final _repo = WordsRepository();
void _confirmClearHistory() {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Row(
children: [
GradientStar(size: 20),
SizedBox(width: 8),
Text('Очистить историю?'),
],
),
content: const Text(
'Все сохранённые записи гаданий и жребиев с датами будут удалены.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Отмена'),
),
FilledButton(
onPressed: () async {
Navigator.pop(ctx);
await _repo.clearHistory();
setState(() {});
HapticFeedback.mediumImpact();
},
style: FilledButton.styleFrom(backgroundColor: Colors.red.shade800),
child: const Text('Очистить'),
),
],
),
);
}
void _copyEntry(HistoryEntry entry) {
final text =
'✨ Оракул 999 — Запись из Истории ✨\n'
'Время: ${entry.formattedDate}\n'
'Тип: ${entry.readingType}${entry.positionTitle != null ? ' (${entry.positionTitle})' : ''}\n'
'Знак №${entry.formattedSessionNumber}: ${entry.word.toUpperCase()}\n'
'Часть речи: ${entry.partOfSpeech}\n\n'
'🔮 Толкование:\n${entry.symbolicMeaning}';
Clipboard.setData(ClipboardData(text: text));
HapticFeedback.lightImpact();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Row(
children: [
GradientStar(size: 18),
SizedBox(width: 10),
Expanded(child: Text('Запись скопирована в буфер обмена')),
],
),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
final historyList = _repo.history;
return Scaffold(
appBar: AppBar(
title: const Row(
children: [
GradientStar(size: 24),
SizedBox(width: 10),
Text(
'История гаданий',
style: TextStyle(fontWeight: FontWeight.w900),
),
],
),
actions: [
if (historyList.isNotEmpty)
IconButton(
tooltip: 'Очистить историю',
icon: const Icon(Icons.delete_outline_rounded),
onPressed: _confirmClearHistory,
),
],
),
body: historyList.isEmpty
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const GradientStar(size: 48),
const SizedBox(height: 16),
Text(
'История пока пуста',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Text(
'Совершите жребий или сохраните выпавший символ, и он появится здесь с точной датой и временем.',
textAlign: TextAlign.center,
style: TextStyle(color: theme.colorScheme.outline),
),
),
],
),
)
: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
itemCount: historyList.length,
separatorBuilder: (_, _) => const SizedBox(height: 10),
itemBuilder: (context, index) {
final item = historyList[index];
return Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
side: BorderSide(
color: const Color(0xFFFFD54F).withValues(alpha: 0.2),
),
),
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),
),
const SizedBox(width: 5),
Text(
item.formattedDate,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Color(0xFFFFD54F),
),
),
],
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
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,
),
),
),
],
),
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),
// 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,
),
),
),
],
),
),
);
},
),
);
}
}
+451
View File
@@ -0,0 +1,451 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../models/word_model.dart';
import '../services/words_repository.dart';
import '../widgets/gradient_star_badge.dart';
import '../widgets/word_card_widget.dart';
class HomeSearchScreen extends StatefulWidget {
const HomeSearchScreen({super.key});
@override
State<HomeSearchScreen> createState() => _HomeSearchScreenState();
}
class _HomeSearchScreenState extends State<HomeSearchScreen> {
final _repo = WordsRepository();
final _searchController = TextEditingController();
final _focusNode = FocusNode();
WordItem? _currentWord;
List<WordItem> _searchResults = [];
bool _showKeypad = true;
@override
void initState() {
super.initState();
_currentWord = _repo.getWordBySessionNumber(0) ?? _repo.allWords.first;
_searchController.addListener(_onSearchChanged);
}
@override
void dispose() {
_searchController.removeListener(_onSearchChanged);
_searchController.dispose();
_focusNode.dispose();
super.dispose();
}
void _onSearchChanged() {
final query = _searchController.text.trim();
if (query.isEmpty) {
setState(() {
_searchResults = [];
});
return;
}
final results = _repo.search(query);
setState(() {
_searchResults = results;
if (results.isNotEmpty) {
_currentWord = results.first;
}
});
}
void _setWord(WordItem word, {bool updateText = false}) {
setState(() {
_currentWord = word;
if (updateText) {
_searchController.text = word.sessionNumber.toString();
}
});
HapticFeedback.selectionClick();
}
void _onKeypadTap(String val) {
HapticFeedback.lightImpact();
String currentText = _searchController.text;
if (val == 'C') {
_searchController.clear();
return;
}
if (val == '⌫') {
if (currentText.isNotEmpty) {
_searchController.text = currentText.substring(0, currentText.length - 1);
_searchController.selection = TextSelection.fromPosition(
TextPosition(offset: _searchController.text.length),
);
}
return;
}
// Append digit
if (currentText.length >= 3) {
_searchController.text = val;
} else {
final newText = currentText + val;
final num = int.tryParse(newText);
if (num != null && num <= 999) {
_searchController.text = newText;
} else {
_searchController.text = val;
}
}
_searchController.selection = TextSelection.fromPosition(
TextPosition(offset: _searchController.text.length),
);
}
void _goToNext() {
if (_currentWord == null) return;
final next = _repo.getNextWord(_currentWord!.sessionNumber);
_setWord(next, updateText: true);
}
void _goToPrevious() {
if (_currentWord == null) return;
final prev = _repo.getPreviousWord(_currentWord!.sessionNumber);
_setWord(prev, updateText: true);
}
void _goToRandom() {
final rnd = _repo.getRandomWord();
_setWord(rnd, updateText: true);
}
void _reshuffleSession() {
_repo.reshuffleSessionNumbers();
final first = _repo.getWordBySessionNumber(0) ?? _repo.allWords.first;
setState(() {
_currentWord = first;
_searchController.clear();
_searchResults = [];
});
HapticFeedback.heavyImpact();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Row(
children: [
GradientStar(size: 20),
SizedBox(width: 10),
Expanded(
child: Text(
'Случайный порядок 1000 чисел перетасован заново!',
style: TextStyle(fontWeight: FontWeight.w600),
),
),
],
),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
return Scaffold(
appBar: AppBar(
title: Row(
children: [
const GradientStar(size: 24),
const SizedBox(width: 10),
const Text(
'Оракул 999',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w900,
letterSpacing: 0.5,
),
),
],
),
actions: [
IconButton(
tooltip: 'Перетасовать числа сессии (#000..#999)',
icon: const Icon(Icons.refresh_rounded),
onPressed: _reshuffleSession,
),
IconButton(
tooltip: _showKeypad ? 'Скрыть цифровую панель' : 'Показать цифровую панель',
icon: Icon(_showKeypad ? Icons.dialpad_outlined : Icons.dialpad),
onPressed: () {
setState(() => _showKeypad = !_showKeypad);
},
),
IconButton(
tooltip: 'Случайный жребий',
icon: const Icon(Icons.shuffle_rounded),
onPressed: _goToRandom,
),
],
),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Search & Number Input Bar
TextField(
controller: _searchController,
focusNode: _focusNode,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: 'Введите номер (#000..#999) или символ',
hintText: 'Например: 777 или огонь',
prefixIcon: const Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: GradientStar(size: 18),
),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear_rounded),
onPressed: () {
_searchController.clear();
_focusNode.unfocus();
},
)
: null,
filled: true,
fillColor: isDark
? const Color(0xFF1B1D30)
: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.4),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
borderSide: BorderSide(
color: const Color(0xFFFFD54F).withValues(alpha: 0.3),
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
borderSide: BorderSide(
color: const Color(0xFFFFD54F).withValues(alpha: 0.25),
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
borderSide: const BorderSide(
color: Color(0xFFFFD54F),
width: 1.8,
),
),
),
),
// Search matches dropdown list if query produced text matches
if (_searchResults.length > 1 && _searchController.text.isNotEmpty) ...[
const SizedBox(height: 8),
Container(
constraints: const BoxConstraints(maxHeight: 140),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF161828) : theme.colorScheme.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.3),
),
),
child: ListView.separated(
shrinkWrap: true,
padding: const EdgeInsets.symmetric(vertical: 4),
itemCount: _searchResults.length > 10 ? 10 : _searchResults.length,
separatorBuilder: (_, _) => const Divider(height: 1),
itemBuilder: (context, idx) {
final item = _searchResults[idx];
final isSelected = item.sessionNumber == _currentWord?.sessionNumber;
return ListTile(
dense: true,
selected: isSelected,
leading: GradientStarBadge(
text: '#${item.formattedSessionNumber}',
size: 14,
),
title: Text(
item.word.toUpperCase(),
style: const TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(
item.description,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 11),
),
trailing: Text(
item.partOfSpeech,
style: TextStyle(
fontSize: 11,
color: theme.colorScheme.outline,
),
),
onTap: () {
_setWord(item, updateText: false);
},
);
},
),
),
],
const SizedBox(height: 14),
// Main Sacred Word Card Display
if (_currentWord != null)
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
transitionBuilder: (child, animation) {
return FadeTransition(
opacity: animation,
child: SlideTransition(
position: Tween<Offset>(
begin: const Offset(0.0, 0.04),
end: Offset.zero,
).animate(animation),
child: child,
),
);
},
child: WordCardWidget(
key: ValueKey('${_currentWord!.id}_${_currentWord!.sessionNumber}'),
word: _currentWord!,
onNext: _goToNext,
onPrevious: _goToPrevious,
onRandom: _goToRandom,
),
)
else
Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text(
'Символ с таким номером не найден.',
textAlign: TextAlign.center,
style: TextStyle(color: theme.colorScheme.error),
),
),
),
const SizedBox(height: 14),
// Interactive Numeric Keypad (1..9, C, 0, ⌫)
if (_showKeypad) ...[
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: isDark
? const Color(0xFF17192A)
: theme.colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.25),
),
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Row(
children: [
GradientStar(size: 14),
SizedBox(width: 6),
Text(
'Случайный жребий числа:',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: Color(0xFFFFD54F),
),
),
],
),
Text(
'000 — 999',
style: TextStyle(
fontSize: 11,
color: theme.colorScheme.outline,
),
),
],
),
const SizedBox(height: 10),
_buildKeypadRow(['1', '2', '3']),
const SizedBox(height: 8),
_buildKeypadRow(['4', '5', '6']),
const SizedBox(height: 8),
_buildKeypadRow(['7', '8', '9']),
const SizedBox(height: 8),
_buildKeypadRow(['C', '0', '⌫']),
],
),
),
const SizedBox(height: 16),
],
],
),
),
),
);
}
Widget _buildKeypadRow(List<String> keys) {
return Row(
children: keys.map((key) {
final isSpecial = key == 'C' || key == '⌫';
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
return Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Material(
color: isSpecial
? const Color(0xFF2A2D4A)
: isDark
? const Color(0xFF20233A)
: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(14),
elevation: 1,
child: InkWell(
onTap: () => _onKeypadTap(key),
borderRadius: BorderRadius.circular(14),
child: Container(
height: 46,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: isSpecial
? const Color(0xFFFFD54F).withValues(alpha: 0.4)
: Colors.white10,
),
),
child: Text(
key,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isSpecial
? const Color(0xFFFFF9C4)
: isDark
? Colors.white
: Colors.black87,
),
),
),
),
),
),
);
}).toList(),
);
}
}
+298
View File
@@ -0,0 +1,298 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../models/history_entry_model.dart';
import '../models/word_model.dart';
import '../services/words_repository.dart';
import '../widgets/gradient_star_badge.dart';
import '../widgets/word_card_widget.dart';
class OracleSpreadScreen extends StatefulWidget {
const OracleSpreadScreen({super.key});
@override
State<OracleSpreadScreen> createState() => _OracleSpreadScreenState();
}
class _OracleSpreadScreenState extends State<OracleSpreadScreen> {
final _repo = WordsRepository();
int _selectedMode = 0; // 0 = Single Card (Жребий момента), 1 = Triad (3 карты)
WordItem? _singleDraw;
List<WordItem> _triadDraw = [];
bool _isGenerating = false;
@override
void initState() {
super.initState();
_singleDraw = _repo.getRandomWord();
}
Future<void> _performSingleDraw({bool saveHistory = true}) async {
setState(() => _isGenerating = true);
HapticFeedback.mediumImpact();
await Future.delayed(const Duration(milliseconds: 250));
final word = _repo.getRandomWord();
setState(() {
_singleDraw = word;
_isGenerating = false;
});
if (saveHistory) {
final entry = HistoryEntry(
id: DateTime.now().millisecondsSinceEpoch.toString(),
timestamp: DateTime.now(),
word: word.word,
sessionNumber: word.sessionNumber,
partOfSpeech: word.partOfSpeech,
symbolicMeaning: word.description,
readingType: 'Жребий момента (1 символ)',
);
await _repo.addHistoryEntry(entry);
}
}
Future<void> _performTriadDraw() async {
setState(() => _isGenerating = true);
HapticFeedback.heavyImpact();
await Future.delayed(const Duration(milliseconds: 300));
final words = <WordItem>[];
final titles = [
'Истоки / Скрытая причина',
'Настоящее / Вызов',
'Совет / Исход',
];
while (words.length < 3) {
final w = _repo.getRandomWord();
if (!words.any((item) => item.id == w.id)) {
words.add(w);
}
}
setState(() {
_triadDraw = words;
_isGenerating = false;
});
for (int i = 0; i < words.length; i++) {
final entry = HistoryEntry(
id: '${DateTime.now().millisecondsSinceEpoch}_$i',
timestamp: DateTime.now(),
word: words[i].word,
sessionNumber: words[i].sessionNumber,
partOfSpeech: words[i].partOfSpeech,
symbolicMeaning: words[i].description,
readingType: 'Триада судьбы',
positionTitle: titles[i],
);
await _repo.addHistoryEntry(entry);
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
return Scaffold(
appBar: AppBar(
title: const Row(
children: [
GradientStar(size: 24),
SizedBox(width: 10),
Text(
'Расклады Оракула',
style: TextStyle(fontWeight: FontWeight.w900),
),
],
),
),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Mode Selector (1 символ / Триада 3 символа)
Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1B1D30) : theme.colorScheme.surfaceContainerHigh,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.3),
),
),
child: Row(
children: [
Expanded(
child: InkWell(
onTap: () {
setState(() => _selectedMode = 0);
if (_singleDraw == null) _performSingleDraw(saveHistory: false);
},
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: _selectedMode == 0
? const Color(0xFF2A2D4A)
: Colors.transparent,
borderRadius: BorderRadius.circular(12),
border: _selectedMode == 0
? Border.all(color: const Color(0xFFFFD54F).withValues(alpha: 0.5))
: null,
),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const GradientStar(size: 14),
const SizedBox(width: 6),
Text(
'Жребий момента (1)',
style: TextStyle(
fontWeight: FontWeight.bold,
color: _selectedMode == 0
? const Color(0xFFFFF9C4)
: theme.colorScheme.outline,
),
),
],
),
),
),
),
Expanded(
child: InkWell(
onTap: () {
setState(() => _selectedMode = 1);
if (_triadDraw.isEmpty) _performTriadDraw();
},
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: _selectedMode == 1
? const Color(0xFF2A2D4A)
: Colors.transparent,
borderRadius: BorderRadius.circular(12),
border: _selectedMode == 1
? Border.all(color: const Color(0xFFFFD54F).withValues(alpha: 0.5))
: null,
),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const GradientStar(size: 14),
const SizedBox(width: 6),
Text(
'Триада судьбы (3)',
style: TextStyle(
fontWeight: FontWeight.bold,
color: _selectedMode == 1
? const Color(0xFFFFF9C4)
: theme.colorScheme.outline,
),
),
],
),
),
),
),
],
),
),
const SizedBox(height: 16),
// Action draw button
FilledButton.icon(
onPressed: _isGenerating
? null
: () {
if (_selectedMode == 0) {
_performSingleDraw(saveHistory: true);
} else {
_performTriadDraw();
}
},
icon: const GradientStar(size: 20),
label: Text(
_selectedMode == 0 ? 'БРОСИТЬ ЖРЕБИЙ МОМЕНТА' : 'РАСКРЫТЬ ТРИАДУ СУДЬБЫ',
style: const TextStyle(
fontWeight: FontWeight.w900,
letterSpacing: 0.8,
),
),
style: FilledButton.styleFrom(
backgroundColor: const Color(0xFF2A2D4A),
foregroundColor: const Color(0xFFFFF9C4),
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
side: const BorderSide(
color: Color(0xFFFFD54F),
width: 1.2,
),
),
),
),
const SizedBox(height: 20),
if (_isGenerating)
const Center(
child: Padding(
padding: EdgeInsets.all(40.0),
child: Column(
children: [
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFFFD54F)),
),
SizedBox(height: 16),
Text(
'Синхронизация с полем оракула...',
style: TextStyle(fontStyle: FontStyle.italic),
),
],
),
),
)
else if (_selectedMode == 0 && _singleDraw != null)
WordCardWidget(
word: _singleDraw!,
positionTitle: 'Символ момента',
onRandom: () => _performSingleDraw(saveHistory: true),
)
else if (_selectedMode == 1 && _triadDraw.isNotEmpty)
Column(
children: [
WordCardWidget(
word: _triadDraw[0],
positionTitle: '1. Истоки / Скрытая причина',
),
const SizedBox(height: 14),
WordCardWidget(
word: _triadDraw[1],
positionTitle: '2. Настоящее / Вызов',
),
const SizedBox(height: 14),
WordCardWidget(
word: _triadDraw[2],
positionTitle: '3. Совет / Исход',
),
],
),
const SizedBox(height: 24),
],
),
),
),
);
}
}
+186
View File
@@ -0,0 +1,186 @@
import 'dart:convert';
import 'dart:math';
import 'package:shared_preferences/shared_preferences.dart';
import '../data/words_data.dart';
import '../models/history_entry_model.dart';
import '../models/word_model.dart';
class WordsRepository {
static final WordsRepository _instance = WordsRepository._internal();
factory WordsRepository() => _instance;
WordsRepository._internal();
final List<WordItem> _masterWords = List.from(kRussianTop1000Words);
List<WordItem> _sessionWords = [];
final List<HistoryEntry> _history = [];
bool _isInitialized = false;
List<WordItem> get allWords => List.unmodifiable(_sessionWords);
int get totalWords => _sessionWords.length;
List<HistoryEntry> get history => List.unmodifiable(_history);
Future<void> init() async {
if (_isInitialized) return;
// Always reshuffle session numbers on startup for true synchronicity & randomization
reshuffleSessionNumbers();
// Load history from persistence
try {
final prefs = await SharedPreferences.getInstance();
final historyJsonList = prefs.getStringList('oracle_history_entries') ?? [];
_history.clear();
for (final str in historyJsonList) {
try {
final map = jsonDecode(str) as Map<String, dynamic>;
_history.add(HistoryEntry.fromMap(map));
} catch (_) {}
}
} catch (_) {}
_isInitialized = true;
}
/// Cryptographic/pseudo-random Fisher-Yates shuffle to map 000..999 to words for the current session
void reshuffleSessionNumbers() {
final random = Random();
final indices = List<int>.generate(_masterWords.length, (i) => i);
indices.shuffle(random);
final mappedList = <WordItem>[];
for (int i = 0; i < _masterWords.length; i++) {
final baseWord = _masterWords[indices[i]];
// i is the dynamic sessionNumber (0..999)
final sessionItem = baseWord.copyWith(sessionNumber: i);
mappedList.add(sessionItem);
}
_sessionWords = mappedList;
}
WordItem? getWordBySessionNumber(int sessionNum) {
if (sessionNum < 0 || sessionNum >= _sessionWords.length) return null;
return _sessionWords[sessionNum];
}
WordItem? getWordById(int id) {
return getWordBySessionNumber(id);
}
WordItem getRandomWord() {
if (_sessionWords.isEmpty) {
return _masterWords.first;
}
final random = Random();
final index = random.nextInt(_sessionWords.length);
return _sessionWords[index];
}
WordItem getNextWord(int currentSessionNum) {
if (_sessionWords.isEmpty) return getRandomWord();
final nextId = (currentSessionNum + 1) % _sessionWords.length;
return _sessionWords[nextId];
}
WordItem getPreviousWord(int currentSessionNum) {
if (_sessionWords.isEmpty) return getRandomWord();
final prevId = (currentSessionNum - 1 + _sessionWords.length) % _sessionWords.length;
return _sessionWords[prevId];
}
List<WordItem> search(String rawQuery) {
final query = rawQuery.trim().toLowerCase();
if (query.isEmpty) return _sessionWords;
// Check if query is a number (e.g. 0, 00, 000, 42, 042, 999)
final number = int.tryParse(query);
if (number != null && number >= 0 && number < _sessionWords.length) {
final exact = _sessionWords[number];
final matches = _sessionWords.where((w) {
if (w.sessionNumber == number) return false;
final idStr = w.sessionNumber.toString();
final paddedStr = w.formattedSessionNumber;
return idStr.startsWith(query) || paddedStr.startsWith(query);
}).take(30).toList();
return [exact, ...matches];
}
// Partial numeric match
if (RegExp(r'^\d+$').hasMatch(query)) {
return _sessionWords.where((w) {
final idStr = w.sessionNumber.toString();
final paddedStr = w.formattedSessionNumber;
return idStr.startsWith(query) || paddedStr.startsWith(query);
}).take(30).toList();
}
// Text search in word, description, category, and part of speech
final exact = <WordItem>[];
final startsWith = <WordItem>[];
final contains = <WordItem>[];
for (final w in _sessionWords) {
final lower = w.word.toLowerCase();
if (lower == query) {
exact.add(w);
} else if (lower.startsWith(query)) {
startsWith.add(w);
} else if (lower.contains(query) ||
w.description.toLowerCase().contains(query) ||
w.category.toLowerCase().contains(query) ||
w.partOfSpeech.toLowerCase().contains(query)) {
contains.add(w);
}
}
return [...exact, ...startsWith, ...contains];
}
List<String> getCategories() {
final set = <String>{'Все'};
for (final w in _sessionWords) {
if (w.category.isNotEmpty) {
set.add(w.category);
}
}
return set.toList();
}
List<String> getPartsOfSpeech() {
final set = <String>{'Все'};
for (final w in _sessionWords) {
if (w.partOfSpeech.isNotEmpty) {
set.add(w.partOfSpeech);
}
}
return set.toList();
}
// --- History Management ---
Future<void> addHistoryEntry(HistoryEntry entry) async {
_history.insert(0, entry);
if (_history.length > 500) {
_history.removeRange(500, _history.length);
}
await _saveHistoryToPrefs();
}
Future<void> deleteHistoryEntry(String id) async {
_history.removeWhere((e) => e.id == id);
await _saveHistoryToPrefs();
}
Future<void> clearHistory() async {
_history.clear();
await _saveHistoryToPrefs();
}
Future<void> _saveHistoryToPrefs() async {
try {
final prefs = await SharedPreferences.getInstance();
final list = _history.map((e) => jsonEncode(e.toMap())).toList();
await prefs.setStringList('oracle_history_entries', list);
} catch (_) {}
}
}
+108
View File
@@ -0,0 +1,108 @@
import 'package:flutter/material.dart';
class GradientStar extends StatelessWidget {
final double size;
final bool hasGlow;
const GradientStar({
super.key,
this.size = 24,
this.hasGlow = true,
});
@override
Widget build(BuildContext context) {
Widget starIcon = ShaderMask(
shaderCallback: (Rect bounds) {
return const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFFFFFFFF), // Pure white
Color(0xFFFFF9C4), // Light lemon
Color(0xFFFFEE58), // Bright yellow
Color(0xFFFFCA28), // Golden amber
],
stops: [0.0, 0.35, 0.7, 1.0],
).createShader(bounds);
},
child: Icon(
Icons.star_rounded,
size: size,
color: Colors.white,
),
);
if (!hasGlow) return starIcon;
return Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: const Color(0xFFFFD54F).withValues(alpha: 0.35),
blurRadius: size * 0.4,
spreadRadius: size * 0.1,
),
],
),
child: starIcon,
);
}
}
class GradientStarBadge extends StatelessWidget {
final String text;
final double size;
const GradientStarBadge({
super.key,
required this.text,
this.size = 20,
});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
const Color(0xFF2A2D4A),
const Color(0xFF1B1D30),
],
),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.5),
width: 1.2,
),
boxShadow: [
BoxShadow(
color: const Color(0xFFFFD54F).withValues(alpha: 0.15),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
GradientStar(size: size),
const SizedBox(width: 6),
Text(
text,
style: const TextStyle(
fontWeight: FontWeight.w900,
fontSize: 14,
letterSpacing: 0.5,
color: Color(0xFFFFF9C4),
),
),
],
),
);
}
}
+400
View File
@@ -0,0 +1,400 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../models/history_entry_model.dart';
import '../models/word_model.dart';
import '../services/words_repository.dart';
import 'gradient_star_badge.dart';
class WordCardWidget extends StatefulWidget {
final WordItem word;
final VoidCallback? onNext;
final VoidCallback? onPrevious;
final VoidCallback? onRandom;
final String? positionTitle; // Optional title for spread positions
const WordCardWidget({
super.key,
required this.word,
this.onNext,
this.onPrevious,
this.onRandom,
this.positionTitle,
});
@override
State<WordCardWidget> createState() => _WordCardWidgetState();
}
class _WordCardWidgetState extends State<WordCardWidget> {
final _repo = WordsRepository();
bool _savedToHistory = false;
@override
void didUpdateWidget(covariant WordCardWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.word.id != widget.word.id ||
oldWidget.word.sessionNumber != widget.word.sessionNumber) {
_savedToHistory = false;
}
}
Color _getPosColor(String pos) {
switch (pos.toLowerCase()) {
case 'существительное':
return const Color(0xFF64B5F6); // Celestial Blue
case 'глагол':
return const Color(0xFF81C784); // Vital Green
case 'прилагательное':
return const Color(0xFFFFD54F); // Golden
case 'наречие':
case 'наречие-местоимение':
return const Color(0xFFBA68C8); // Mystic Violet
case 'местоимение':
case 'местоименное прил.':
return const Color(0xFF4DD0E1); // Cyan
case 'предлог':
case 'союз':
case 'частица':
return const Color(0xFFFF8A65); // Coral Ember
default:
return const Color(0xFF90A4AE);
}
}
Future<void> _recordToHistory() async {
if (_savedToHistory) return;
final entry = HistoryEntry(
id: DateTime.now().millisecondsSinceEpoch.toString(),
timestamp: DateTime.now(),
word: widget.word.word,
sessionNumber: widget.word.sessionNumber,
partOfSpeech: widget.word.partOfSpeech,
symbolicMeaning: widget.word.description,
readingType: widget.positionTitle ?? 'Жребий номера',
positionTitle: widget.positionTitle,
);
await _repo.addHistoryEntry(entry);
if (!mounted) return;
setState(() => _savedToHistory = true);
HapticFeedback.mediumImpact();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
const GradientStar(size: 18),
const SizedBox(width: 10),
Expanded(
child: Text('Символ «${widget.word.word}» сохранён в историю'),
),
],
),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
);
}
void _copyToClipboard(BuildContext context) {
final now = DateTime.now();
final day = now.day.toString().padLeft(2, '0');
final month = now.month.toString().padLeft(2, '0');
final year = now.year.toString();
final hour = now.hour.toString().padLeft(2, '0');
final min = now.minute.toString().padLeft(2, '0');
final text =
'✨ Оракул 999 — Толкование символа ✨\n'
'Дата и время: $day.$month.$year $hour:$min\n'
'Знак №${widget.word.formattedSessionNumber}: ${widget.word.word.toUpperCase()}\n'
'Аспект: ${widget.word.partOfSpeech} • ${widget.word.category}\n\n'
'🔮 Символическое значение:\n${widget.word.description}';
Clipboard.setData(ClipboardData(text: text));
HapticFeedback.lightImpact();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
const GradientStar(size: 18),
const SizedBox(width: 10),
Expanded(child: Text('Толкование «${widget.word.word}» скопировано')),
],
),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
final posColor = _getPosColor(widget.word.partOfSpeech);
return Card(
elevation: 8,
shadowColor: const Color(0xFFFFD54F).withValues(alpha: 0.18),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
side: BorderSide(
color: const Color(0xFFFFD54F).withValues(alpha: 0.25),
width: 1.2,
),
),
clipBehavior: Clip.antiAlias,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDark
? [
const Color(0xFF1E2138),
const Color(0xFF121424),
]
: [
const Color(0xFFF9F9FF),
const Color(0xFFEFF1F9),
],
),
),
padding: const EdgeInsets.all(22),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Optional spread position banner (e.g. "Исток / Прошлое")
if (widget.positionTitle != null) ...[
Container(
margin: const EdgeInsets.only(bottom: 12),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: const Color(0xFFFFD54F).withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.4),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const GradientStar(size: 14),
const SizedBox(width: 6),
Text(
widget.positionTitle!,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Color(0xFFFFD54F),
letterSpacing: 0.5,
),
),
],
),
),
],
// Top Row: Gradient Star Number Badge and Action Buttons
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GradientStarBadge(
text: '#${widget.word.formattedSessionNumber} / 999',
size: 18,
),
Row(
children: [
IconButton(
tooltip: 'Скопировать толкование',
icon: const Icon(Icons.copy_rounded, size: 20),
onPressed: () => _copyToClipboard(context),
),
IconButton(
tooltip: _savedToHistory ? 'Сохранено в историю' : 'Сохранить в историю',
icon: Icon(
_savedToHistory ? Icons.bookmark_added_rounded : Icons.bookmark_add_outlined,
color: _savedToHistory ? const Color(0xFFFFD54F) : null,
size: 22,
),
onPressed: _recordToHistory,
),
],
),
],
),
const SizedBox(height: 14),
// Big Word Title
Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6.0),
child: Text(
widget.word.word.toUpperCase(),
textAlign: TextAlign.center,
style: theme.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.w900,
letterSpacing: 1.5,
color: isDark ? const Color(0xFFFFF9C4) : const Color(0xFF1B1D30),
),
),
),
),
// Part of Speech & Category Badges
Center(
child: Wrap(
spacing: 8,
runSpacing: 6,
alignment: WrapAlignment.center,
children: [
Chip(
avatar: Icon(Icons.auto_awesome, size: 14, color: posColor),
label: Text(
widget.word.partOfSpeech,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12,
color: posColor,
),
),
backgroundColor: posColor.withValues(alpha: 0.12),
side: BorderSide(color: posColor.withValues(alpha: 0.3)),
padding: const EdgeInsets.symmetric(horizontal: 4),
),
if (widget.word.category.isNotEmpty)
Chip(
label: Text(
widget.word.category,
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.white70 : Colors.black87,
),
),
backgroundColor: isDark
? Colors.white.withValues(alpha: 0.08)
: Colors.black.withValues(alpha: 0.05),
side: BorderSide.none,
padding: const EdgeInsets.symmetric(horizontal: 2),
),
],
),
),
const SizedBox(height: 16),
Divider(
height: 1,
color: isDark ? Colors.white12 : Colors.black12,
),
const SizedBox(height: 14),
// Symbolic Divination Meaning Box
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: isDark
? const Color(0xFF141729)
: const Color(0xFFFFFFFF),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: const Color(0xFFFFD54F).withValues(alpha: 0.2),
),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: isDark ? 0.2 : 0.05),
blurRadius: 6,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const GradientStar(size: 16),
const SizedBox(width: 8),
Text(
'СИМВОЛИЧЕСКОЕ ЗНАЧЕНИЕ',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w900,
letterSpacing: 1.0,
color: const Color(0xFFFFD54F),
),
),
],
),
const SizedBox(height: 10),
Text(
widget.word.description,
style: theme.textTheme.bodyLarge?.copyWith(
height: 1.5,
fontSize: 14.5,
color: isDark ? const Color(0xFFE2E4F0) : const Color(0xFF2C3042),
),
),
],
),
),
const SizedBox(height: 18),
// Navigation Controls Row
Row(
children: [
Expanded(
child: OutlinedButton.icon(
onPressed: widget.onPrevious,
icon: const Icon(Icons.arrow_back_ios_new_rounded, size: 14),
label: const Text('Пред.'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
),
),
),
const SizedBox(width: 8),
IconButton.filledTonal(
tooltip: 'Случайный жребий',
onPressed: widget.onRandom,
icon: const GradientStar(size: 20),
style: IconButton.styleFrom(
padding: const EdgeInsets.all(12),
backgroundColor: const Color(0xFF2A2D4A),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
side: BorderSide(
color: const Color(0xFFFFD54F).withValues(alpha: 0.3),
),
),
),
),
const SizedBox(width: 8),
Expanded(
child: FilledButton.icon(
onPressed: widget.onNext,
icon: const Text('След.'),
label: const Icon(Icons.arrow_forward_ios_rounded, size: 14),
style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
),
),
),
],
),
],
),
),
);
}
}