210 lines
7.9 KiB
Dart
210 lines
7.9 KiB
Dart
import 'package:didvan/config/design_config.dart';
|
||
import 'package:didvan/config/theme_data.dart';
|
||
import 'package:didvan/models/ai/ai_chat_args.dart';
|
||
import 'package:didvan/models/ai/tools_model.dart';
|
||
import 'package:didvan/routes/routes.dart';
|
||
import 'package:didvan/services/webview.dart';
|
||
import 'package:didvan/views/ai/ai_state.dart';
|
||
import 'package:didvan/views/widgets/didvan/text.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_svg/flutter_svg.dart';
|
||
import 'package:provider/provider.dart';
|
||
|
||
class AiSectionBNB extends StatelessWidget {
|
||
final int currentTabIndex;
|
||
final void Function(int index) onTabChanged;
|
||
|
||
const AiSectionBNB(
|
||
{Key? key, required this.currentTabIndex, required this.onTabChanged})
|
||
: super(key: key);
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
const String cameraSolid = 'lib/assets/icons/houshanNav/imagegeneratorS.svg';
|
||
const String cameraRegular = 'lib/assets/icons/houshanNav/imagegeneratorU.svg';
|
||
const String micSolid = 'lib/assets/icons/houshanNav/aichatS.svg';
|
||
const String micRegular = 'lib/assets/icons/houshanNav/aichatU.svg';
|
||
const String aiSolid = 'lib/assets/icons/houshanNav/houshan.svg';
|
||
const String aiRegular = 'lib/assets/icons/houshanNav/houshan.svg';
|
||
const String searchSolid = 'lib/assets/icons/houshanNav/searchS.svg';
|
||
const String searchRegular = 'lib/assets/icons/houshanNav/searchU.svg';
|
||
const String translateSolid = 'lib/assets/icons/houshanNav/translateS.svg';
|
||
const String translateRegular = 'lib/assets/icons/houshanNav/translateU.svg';
|
||
|
||
return Container(
|
||
height: 72,
|
||
decoration: BoxDecoration(
|
||
color: Theme.of(context).colorScheme.surface,
|
||
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: const Color(0XFF1B3C59).withValues(alpha: 0.15),
|
||
blurRadius: 8,
|
||
spreadRadius: 0,
|
||
offset: const Offset(0, -8),
|
||
)
|
||
],
|
||
),
|
||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||
child: Row(
|
||
children: [
|
||
_AiNavBarItem(
|
||
isSelected: currentTabIndex == 0,
|
||
title: 'عکس ساز',
|
||
selectedIcon: cameraSolid,
|
||
unselectedIcon: cameraRegular,
|
||
onTap: () {
|
||
final aiState = context.read<AiState>();
|
||
if (aiState.tools != null && aiState.tools!.isNotEmpty) {
|
||
final Tools imageGenTool = aiState.tools![0]; // ابزار عکس ساز
|
||
if (imageGenTool.bots != null && imageGenTool.bots!.isNotEmpty) {
|
||
final bot = imageGenTool.bots!.first;
|
||
Navigator.of(context).pushNamed(
|
||
Routes.aiChat,
|
||
arguments: AiChatArgs(bot: bot, isTool: imageGenTool.bots),
|
||
);
|
||
}
|
||
} else {
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
const SnackBar(content: Text('ابزار عکس ساز در حال بارگذاری است...')),
|
||
);
|
||
}
|
||
},
|
||
),
|
||
_AiNavBarItem(
|
||
isSelected: currentTabIndex == 1,
|
||
title: 'چت صوتی',
|
||
selectedIcon: micSolid,
|
||
unselectedIcon: micRegular,
|
||
onTap: () {
|
||
NativeWebViewLauncher.openWebView(
|
||
'https://www.aisada.ir/app/page1.html');
|
||
},
|
||
),
|
||
_AiNavBarItem(
|
||
isSelected: currentTabIndex == 2,
|
||
title: '',
|
||
selectedIcon: aiSolid,
|
||
unselectedIcon: aiRegular,
|
||
onTap: () => onTabChanged(2),
|
||
),
|
||
_AiNavBarItem(
|
||
isSelected: currentTabIndex == 3,
|
||
title: 'جست و جو',
|
||
selectedIcon: searchSolid,
|
||
unselectedIcon: searchRegular,
|
||
onTap: () {
|
||
final aiState = context.read<AiState>();
|
||
// نکته: طبق کد شما، تب جستجو (اندیس ۳) ویجت تحلیل نمودار را نمایش میدهد
|
||
// که از ابزار اندیس ۱ استفاده میکند.
|
||
if (aiState.tools != null && aiState.tools!.length > 1) {
|
||
final Tools chartAnalysisTool = aiState.tools![1];
|
||
if (chartAnalysisTool.bots != null && chartAnalysisTool.bots!.isNotEmpty) {
|
||
final bot = chartAnalysisTool.bots!.first;
|
||
Navigator.of(context).pushNamed(
|
||
Routes.aiChat,
|
||
arguments: AiChatArgs(bot: bot, isTool: chartAnalysisTool.bots),
|
||
);
|
||
}
|
||
} else {
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
const SnackBar(content: Text('ابزار جستجو در حال بارگذاری است...')),
|
||
);
|
||
}
|
||
},
|
||
),
|
||
_AiNavBarItem(
|
||
isSelected: currentTabIndex == 4,
|
||
title: 'ترجمه',
|
||
selectedIcon: translateSolid,
|
||
unselectedIcon: translateRegular,
|
||
onTap: () {
|
||
final aiState = context.read<AiState>();
|
||
if (aiState.tools != null && aiState.tools!.length > 2) {
|
||
final Tools translationToolCategory = aiState.tools![2];
|
||
if (translationToolCategory.bots != null && translationToolCategory.bots!.isNotEmpty) {
|
||
final gptTranslatorBot = translationToolCategory.bots!.first;
|
||
Navigator.of(context).pushNamed(
|
||
Routes.aiChat,
|
||
arguments: AiChatArgs(bot: gptTranslatorBot, isTool: translationToolCategory.bots),
|
||
);
|
||
}
|
||
} else {
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
const SnackBar(content: Text('ابزار ترجمه در حال بارگذاری است...')),
|
||
);
|
||
}
|
||
},
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
|
||
class _AiNavBarItem extends StatelessWidget {
|
||
final VoidCallback onTap;
|
||
final bool isSelected;
|
||
final String title;
|
||
final String selectedIcon;
|
||
final String unselectedIcon;
|
||
|
||
const _AiNavBarItem({
|
||
Key? key,
|
||
required this.isSelected,
|
||
required this.title,
|
||
required this.selectedIcon,
|
||
required this.unselectedIcon,
|
||
required this.onTap,
|
||
}) : super(key: key);
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
|
||
final double iconSize = title.isEmpty ? 50.0 : 32.0;
|
||
|
||
return Expanded(
|
||
child: Tooltip(
|
||
message: title,
|
||
decoration: BoxDecoration(
|
||
color: Theme.of(context).colorScheme.title,
|
||
borderRadius: DesignConfig.highBorderRadius,
|
||
boxShadow: DesignConfig.defaultShadow,
|
||
),
|
||
child: GestureDetector(
|
||
onTap: onTap,
|
||
child: Container(
|
||
color: Colors.transparent,
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
AnimatedContainer(
|
||
padding: const EdgeInsets.all(4),
|
||
duration: DesignConfig.lowAnimationDuration,
|
||
decoration: const BoxDecoration(
|
||
shape: BoxShape.circle,
|
||
),
|
||
child: SvgPicture.asset(
|
||
isSelected ? selectedIcon : unselectedIcon,
|
||
width: iconSize,
|
||
height: iconSize,
|
||
),
|
||
),
|
||
if (title.isNotEmpty)
|
||
Padding(
|
||
padding: const EdgeInsets.only(top: 2.0),
|
||
child: DidvanText(
|
||
title,
|
||
style: Theme.of(context).textTheme.bodySmall,
|
||
color: Theme.of(context).colorScheme.title,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
} |