209 lines
8.4 KiB
Dart
209 lines
8.4 KiB
Dart
// ignore_for_file: library_private_types_in_public_api
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
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/history_ai_chat_state.dart';
|
|
import 'package:didvan/views/home/home.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.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 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: Stack(
|
|
children: [
|
|
SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(bottom: 24),
|
|
child: Column(
|
|
children: [
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
Icon(
|
|
DidvanIcons.ai_solid,
|
|
size: MediaQuery.sizeOf(context).width / 5,
|
|
color: Theme.of(context).colorScheme.title,
|
|
),
|
|
DidvanText(
|
|
'هوشان',
|
|
color: Theme.of(context).colorScheme.title,
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
InkWell(
|
|
onTap: () => ActionSheetUtils(context)
|
|
.botsDialogSelect(
|
|
context: context, state: state),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
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,
|
|
),
|
|
ClipOval(
|
|
child: CachedNetworkImage(
|
|
width: 46,
|
|
height: 46,
|
|
imageUrl: bot.image.toString(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 20.0),
|
|
child: Text(
|
|
"به هوشان, هوش مصنوعی دیدوان خوش آمدید. \nبرای شروع گفتگو پیام مورد نظر خود را در کادر زیر بنویسید.",
|
|
textAlign: TextAlign.center,
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
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,
|
|
),
|
|
)),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 32),
|
|
child: InkWell(
|
|
onTap: () => Navigator.of(context).pushNamed(Routes.aiChat,
|
|
arguments: AiChatArgs(
|
|
bot: bot,
|
|
)),
|
|
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: [
|
|
const SizedBox(
|
|
width: 8,
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 8.0,
|
|
),
|
|
child: Form(
|
|
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),
|
|
),
|
|
))))
|
|
],
|
|
),
|
|
)),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|