182 lines
5.7 KiB
Dart
182 lines
5.7 KiB
Dart
import 'package:didvan/models/ai/tools_model.dart';
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/views/ai/ai.dart';
|
|
import 'package:didvan/views/ai/widgets/hoshan_drawer.dart';
|
|
import 'package:didvan/views/ai_section/widgets/ai_section_bnb.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:didvan/views/widgets/hoshan_app_bar.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:didvan/views/ai/history_ai_chat_state.dart';
|
|
import 'package:didvan/views/ai/ai_state.dart';
|
|
import 'package:didvan/views/ai/widgets/tool_category_view_widget.dart';
|
|
|
|
class ImageGenerationScreen extends StatelessWidget {
|
|
const ImageGenerationScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final aiState = context.watch<AiState>();
|
|
|
|
if (aiState.tools == null || aiState.tools!.isEmpty) {
|
|
if (aiState.loading || aiState.appState == AppState.busy) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
return const Center(
|
|
child: DidvanText('لیست ابزارها هنوز بارگذاری نشده یا خالی است.'));
|
|
}
|
|
final Tools imageGenToolCategory = aiState.tools![0];
|
|
return ToolCategoryViewWidget(tool: imageGenToolCategory);
|
|
}
|
|
}
|
|
|
|
class VoiceChatScreen extends StatelessWidget {
|
|
const VoiceChatScreen({super.key});
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final aiState = context.watch<AiState>();
|
|
|
|
if (aiState.tools == null || aiState.tools!.isEmpty) {
|
|
if (aiState.loading || aiState.appState == AppState.busy) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
return const Center(
|
|
child: DidvanText('لیست ابزارها هنوز بارگذاری نشده یا خالی است.'));
|
|
}
|
|
final Tools voiceChatToolCategory = aiState.tools!.last;
|
|
|
|
return ToolCategoryViewWidget(tool: voiceChatToolCategory);
|
|
}
|
|
}
|
|
|
|
class ChartAnalysisScreen extends StatelessWidget {
|
|
const ChartAnalysisScreen({super.key});
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final aiState = context.watch<AiState>();
|
|
|
|
if (aiState.tools == null || aiState.tools!.isEmpty) {
|
|
if (aiState.loading || aiState.appState == AppState.busy) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
return const Center(
|
|
child: DidvanText('لیست ابزارها هنوز بارگذاری نشده یا خالی است.'));
|
|
}
|
|
|
|
if (aiState.tools!.length < 2) {
|
|
return const Center(
|
|
child:
|
|
DidvanText('ابزار کافی برای "تحلیل نمودار" وجود ندارد.'));
|
|
}
|
|
final Tools chartAnalysisToolCategory = aiState.tools![1];
|
|
|
|
return ToolCategoryViewWidget(tool: chartAnalysisToolCategory);
|
|
}
|
|
}
|
|
|
|
class TranslationScreen extends StatelessWidget {
|
|
const TranslationScreen({super.key});
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final aiState = context.watch<AiState>();
|
|
|
|
if (aiState.tools == null || aiState.tools!.isEmpty) {
|
|
if (aiState.loading || aiState.appState == AppState.busy) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
return const Center(
|
|
child: DidvanText('لیست ابزارها هنوز بارگذاری نشده یا خالی است.'));
|
|
}
|
|
|
|
if (aiState.tools!.length < 3) {
|
|
return const Center(
|
|
child: DidvanText('ابزار کافی برای "ترجمه" وجود ندارد.'));
|
|
}
|
|
final Tools translationToolCategory = aiState.tools![2];
|
|
|
|
return ToolCategoryViewWidget(tool: translationToolCategory);
|
|
}
|
|
}
|
|
|
|
class AiSectionPage extends StatefulWidget {
|
|
const AiSectionPage({super.key});
|
|
|
|
@override
|
|
State<AiSectionPage> createState() => _AiSectionPageState();
|
|
}
|
|
|
|
class _AiSectionPageState extends State<AiSectionPage>
|
|
with SingleTickerProviderStateMixin {
|
|
late TabController _tabController;
|
|
int _currentTabIndex = 2;
|
|
final GlobalKey<ScaffoldState> _aiSectionScaffoldKey =
|
|
GlobalKey<ScaffoldState>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_tabController = TabController(length: 5, vsync: this, initialIndex: 2);
|
|
_tabController.addListener(() {
|
|
if (mounted) {
|
|
setState(() {
|
|
_currentTabIndex = _tabController.index;
|
|
});
|
|
}
|
|
});
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final historyAiChatState = context.read<HistoryAiChatState>();
|
|
if (historyAiChatState.bots.isEmpty) {
|
|
historyAiChatState.getBots();
|
|
}
|
|
|
|
final aiState = context.read<AiState>();
|
|
aiState.page = 0;
|
|
if (aiState.tools == null) {
|
|
aiState.getTools();
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_tabController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
key: _aiSectionScaffoldKey,
|
|
appBar: HoshanAppBar(
|
|
onBack: () {
|
|
final aiState = context.read<AiState>();
|
|
if (aiState.page != 0) {
|
|
aiState.goToAi();
|
|
} else {
|
|
Navigator.of(context).pop();
|
|
}
|
|
},
|
|
withActions: true,
|
|
),
|
|
drawer: HoshanDrawer(scaffKey: _aiSectionScaffoldKey),
|
|
body: TabBarView(
|
|
controller: _tabController,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
children: const [
|
|
ImageGenerationScreen(),
|
|
VoiceChatScreen(),
|
|
Ai(),
|
|
ChartAnalysisScreen(),
|
|
TranslationScreen(),
|
|
],
|
|
),
|
|
bottomNavigationBar: AiSectionBNB(
|
|
currentTabIndex: _currentTabIndex,
|
|
onTabChanged: (index) {
|
|
_tabController.animateTo(index);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
} |