314 lines
16 KiB
Dart
314 lines
16 KiB
Dart
// ignore_for_file: library_private_types_in_public_api
|
|
|
|
import 'dart:math';
|
|
|
|
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/config/theme_data.dart';
|
|
import 'package:didvan/constants/app_icons.dart';
|
|
import 'package:didvan/constants/assets.dart';
|
|
import 'package:didvan/models/ai/ai_chat_args.dart';
|
|
import 'package:didvan/routes/routes.dart';
|
|
import 'package:didvan/utils/action_sheet.dart';
|
|
import 'package:didvan/views/ai/ai_state.dart';
|
|
import 'package:didvan/views/ai/history_ai_chat_state.dart';
|
|
import 'package:didvan/views/ai/tool_screen.dart';
|
|
import 'package:didvan/views/ai/tools_screen.dart';
|
|
import 'package:didvan/views/ai/widgets/message_bar_btn.dart';
|
|
import 'package:didvan/views/home/home.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:didvan/views/widgets/skeleton_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class Ai extends StatefulWidget {
|
|
const Ai({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_AiState createState() => _AiState();
|
|
}
|
|
|
|
class _AiState extends State<Ai> {
|
|
@override
|
|
void initState() {
|
|
final state = context.read<HistoryAiChatState>();
|
|
Future.delayed(
|
|
Duration.zero,
|
|
() {
|
|
if (context.read<HistoryAiChatState>().refresh) {
|
|
context.read<HistoryAiChatState>().getChats();
|
|
context.read<HistoryAiChatState>().refresh = false;
|
|
}
|
|
state.getBots();
|
|
},
|
|
);
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Consumer<AiState>(
|
|
builder: (BuildContext context, state, Widget? child) {
|
|
switch (state.page) {
|
|
case 1:
|
|
return const ToolsScreen();
|
|
case 2:
|
|
return const ToolScreen();
|
|
case 0:
|
|
default:
|
|
return Consumer<HistoryAiChatState>(
|
|
builder: (context, state, child) {
|
|
if (state.bots.isEmpty) {
|
|
return Center(
|
|
child: Image.asset(
|
|
Assets.loadingAnimation,
|
|
width: 60,
|
|
height: 60,
|
|
),
|
|
);
|
|
}
|
|
final bot = state.bot!;
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding:
|
|
const EdgeInsets.only(bottom: 24, top: 32),
|
|
child: Column(
|
|
children: [
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
InkWell(
|
|
onTap: () => ActionSheetUtils(context)
|
|
.botsDialogSelect(
|
|
context: context, state: state),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius:
|
|
BorderRadius.circular(360),
|
|
border: Border.all(
|
|
width: 1,
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.text)),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 8.0, horizontal: 18),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.center,
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
children: [
|
|
Column(
|
|
children: [
|
|
Transform.rotate(
|
|
angle: 180 * pi / 180,
|
|
child: Icon(
|
|
DidvanIcons
|
|
.caret_down_solid,
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.title,
|
|
),
|
|
),
|
|
Icon(
|
|
DidvanIcons
|
|
.caret_down_solid,
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.title,
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
width: 12,
|
|
),
|
|
DidvanText(bot.name.toString(),
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.title),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
width: 12,
|
|
),
|
|
SkeletonImage(
|
|
width: 46,
|
|
height: 46,
|
|
imageUrl: bot.image.toString(),
|
|
borderRadius:
|
|
BorderRadius.circular(360),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
const Padding(
|
|
padding:
|
|
EdgeInsets.symmetric(horizontal: 20.0),
|
|
child: Text(
|
|
"به هوشان؛ هوش مصنوعی دیدوان خوش آمدید. \nبرای شروع گفتگو پیام مورد نظر خود را در کادر زیر بنویسید.",
|
|
textAlign: TextAlign.center,
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 12),
|
|
child: InkWell(
|
|
onTap: () =>
|
|
Navigator.of(context).pushNamed(Routes.aiChat,
|
|
arguments: AiChatArgs(
|
|
bot: bot,
|
|
)),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
boxShadow:
|
|
DesignConfig.defaultShadow,
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.surface,
|
|
border: Border.all(
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.border),
|
|
borderRadius: DesignConfig
|
|
.highBorderRadius),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets
|
|
.symmetric(
|
|
horizontal: 8.0,
|
|
),
|
|
child: Form(
|
|
child: Row(
|
|
children: [
|
|
const MessageBarBtn(
|
|
enable: true,
|
|
icon: DidvanIcons
|
|
.mic_regular),
|
|
const SizedBox(
|
|
width: 8,
|
|
),
|
|
Expanded(
|
|
child:
|
|
TextFormField(
|
|
textInputAction:
|
|
TextInputAction
|
|
.newline,
|
|
style: Theme.of(
|
|
context)
|
|
.textTheme
|
|
.bodyMedium,
|
|
minLines: 1,
|
|
enabled: false,
|
|
decoration:
|
|
InputDecoration(
|
|
border:
|
|
InputBorder
|
|
.none,
|
|
hintText:
|
|
'بنویسید...',
|
|
hintStyle: Theme.of(
|
|
context)
|
|
.textTheme
|
|
.bodySmall!
|
|
.copyWith(
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.disabledText),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: 8,
|
|
),
|
|
MessageBarBtn(
|
|
click: () {
|
|
Navigator.of(context).pushNamed(
|
|
Routes
|
|
.aiChat,
|
|
arguments: AiChatArgs(
|
|
bot:
|
|
bot,
|
|
attach:
|
|
true));
|
|
},
|
|
enable: false,
|
|
icon: Icons
|
|
.attach_file_rounded),
|
|
],
|
|
))))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Padding(
|
|
padding: EdgeInsets.fromLTRB(8, 8, 8, 4),
|
|
child: DidvanText(
|
|
'مدلهای هوش مصنوعی میتوانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید.',
|
|
fontSize: 12,
|
|
),
|
|
)
|
|
],
|
|
)),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
},
|
|
),
|
|
Positioned(
|
|
top: 32,
|
|
right: 0,
|
|
child: InkWell(
|
|
onTap: () => homeScaffKey.currentState!.openDrawer(),
|
|
child: Container(
|
|
width: 46,
|
|
height: 46,
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
borderRadius: const BorderRadius.only(
|
|
topLeft: Radius.circular(12),
|
|
bottomLeft: Radius.circular(12)),
|
|
boxShadow: DesignConfig.defaultShadow),
|
|
child: Icon(
|
|
DidvanIcons.angle_left_light,
|
|
color: Theme.of(context).colorScheme.title,
|
|
),
|
|
)),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|