From c5072a8a8485e118caa14d1c09ef102286b733ab Mon Sep 17 00:00:00 2001 From: AlexIves16 Date: Fri, 27 Mar 2026 18:40:01 +0500 Subject: [PATCH] Add AI test screen with DeepSeek integration --- lib/core/router.dart | 6 + lib/screens/ai_test_screen.dart | 187 ++++++++++++++++++++++++++++++ lib/screens/dashboard_screen.dart | 5 + 3 files changed, 198 insertions(+) create mode 100644 lib/screens/ai_test_screen.dart diff --git a/lib/core/router.dart b/lib/core/router.dart index 0840d0c..d005649 100644 --- a/lib/core/router.dart +++ b/lib/core/router.dart @@ -5,6 +5,7 @@ import '../screens/tasks_screen.dart'; import '../screens/mind_map_screen.dart'; import '../screens/calendar_screen.dart'; import '../screens/alarms_screen.dart'; +import '../screens/ai_test_screen.dart'; class AppRouter { static final GoRouter router = GoRouter( @@ -40,6 +41,11 @@ class AppRouter { name: 'alarms', builder: (context, state) => const AlarmsScreen(), ), + GoRoute( + path: 'ai-test', + name: 'ai-test', + builder: (context, state) => const AiTestScreen(), + ), ], ), ], diff --git a/lib/screens/ai_test_screen.dart b/lib/screens/ai_test_screen.dart new file mode 100644 index 0000000..107ae4e --- /dev/null +++ b/lib/screens/ai_test_screen.dart @@ -0,0 +1,187 @@ +import 'package:flutter/material.dart'; +import '../core/deepseek_service.dart'; + +class AiTestScreen extends StatefulWidget { + const AiTestScreen({super.key}); + + @override + State createState() => _AiTestScreenState(); +} + +class _AiTestScreenState extends State { + final _titleController = TextEditingController(text: 'Создать CRM систему'); + final _descController = TextEditingController( + text: 'Разработка CRM для управления задачами команды с AI планированием', + ); + + bool _isLoading = false; + String _result = ''; + + Future _testGenerateSubtasks() async { + setState(() { + _isLoading = true; + _result = ''; + }); + + try { + final subtasks = await deepSeekService.generateSubtasks( + title: _titleController.text, + description: _descController.text, + ); + + setState(() { + _result = '✅ Сгенерировано подзадач: ${subtasks.length}\n\n'; + for (var task in subtasks) { + _result += '• ${task['title']} (${task['estimatedHours']}ч)\n'; + if (task['description'] != null) { + _result += ' ${task['description']}\n'; + } + } + }); + } catch (e) { + setState(() { + _result = '❌ Ошибка: $e'; + }); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + Future _testPrioritize() async { + setState(() { + _isLoading = true; + _result = ''; + }); + + try { + final priority = await deepSeekService.prioritizeTask( + title: _titleController.text, + description: _descController.text, + dueDate: DateTime.now().add(const Duration(days: 2)), + ); + + setState(() { + _result = '✅ Приоритет: ${priority.name}'; + }); + } catch (e) { + setState(() { + _result = '❌ Ошибка: $e'; + }); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + Future _testMindMap() async { + setState(() { + _isLoading = true; + _result = ''; + }); + + try { + final nodes = await deepSeekService.generateMindMap( + projectName: _titleController.text, + description: _descController.text, + ); + + setState(() { + _result = '✅ Сгенерировано узлов mind-карты: ${nodes.length}\n\n'; + for (var node in nodes) { + final indent = ' ' * (node['level'] as int); + _result += '$indent• ${node['title']} (уровень ${node['level']})\n'; + } + }); + } catch (e) { + setState(() { + _result = '❌ Ошибка: $e'; + }); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('AI Тест (DeepSeek)'), + ), + body: SingleChildScrollView( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + TextField( + controller: _titleController, + decoration: const InputDecoration( + labelText: 'Название задачи', + border: OutlineInputBorder(), + ), + ), + const SizedBox(height: 16), + TextField( + controller: _descController, + maxLines: 3, + decoration: const InputDecoration( + labelText: 'Описание', + border: OutlineInputBorder(), + ), + ), + const SizedBox(height: 24), + const Text( + 'Тесты AI:', + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + const SizedBox(height: 12), + ElevatedButton.icon( + onPressed: _isLoading ? null : _testGenerateSubtasks, + icon: const Icon(Icons.auto_awesome), + label: const Text('Генерация подзадач'), + ), + const SizedBox(height: 8), + ElevatedButton.icon( + onPressed: _isLoading ? null : _testPrioritize, + icon: const Icon(Icons.priority_high), + label: const Text('Приоритизация задачи'), + ), + const SizedBox(height: 8), + ElevatedButton.icon( + onPressed: _isLoading ? null : _testMindMap, + icon: const Icon(Icons.account_tree), + label: const Text('Mind-карта проекта'), + ), + if (_isLoading) ...[ + const SizedBox(height: 24), + const Center(child: CircularProgressIndicator()), + ], + if (_result.isNotEmpty) ...[ + const SizedBox(height: 24), + Card( + child: Padding( + padding: const EdgeInsets.all(16), + child: SelectableText( + _result, + style: const TextStyle(fontFamily: 'monospace'), + ), + ), + ), + ], + ], + ), + ), + ); + } + + @override + void dispose() { + _titleController.dispose(); + _descController.dispose(); + super.dispose(); + } +} diff --git a/lib/screens/dashboard_screen.dart b/lib/screens/dashboard_screen.dart index f89e01a..6fb10ed 100644 --- a/lib/screens/dashboard_screen.dart +++ b/lib/screens/dashboard_screen.dart @@ -10,6 +10,11 @@ class DashboardScreen extends StatelessWidget { appBar: AppBar( title: const Text('NANAXE CRM'), actions: [ + IconButton( + icon: const Icon(Icons.auto_awesome), + onPressed: () => context.push('/home/ai-test'), + tooltip: 'AI Тест', + ), IconButton( icon: const Icon(Icons.settings), onPressed: () {},