934 lines
46 KiB
Dart
934 lines
46 KiB
Dart
// ignore_for_file: deprecated_member_use
|
|
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:animated_custom_dropdown/custom_dropdown.dart';
|
|
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/models/ai/bot_assistants_model.dart';
|
|
import 'package:didvan/models/ai/bot_assistants_req_model.dart';
|
|
import 'package:didvan/models/ai/bots_model.dart';
|
|
import 'package:didvan/models/ai/file_create_assistants_model.dart';
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/models/view/action_sheet_data.dart';
|
|
import 'package:didvan/models/view/alert_data.dart';
|
|
import 'package:didvan/services/media/media.dart';
|
|
import 'package:didvan/utils/action_sheet.dart';
|
|
import 'package:didvan/utils/extension.dart';
|
|
import 'package:didvan/views/ai/bot_assistants_state.dart';
|
|
import 'package:didvan/views/ai/create_bot_assistants_state.dart';
|
|
import 'package:didvan/views/ai/history_ai_chat_state.dart';
|
|
import 'package:didvan/views/widgets/didvan/button.dart';
|
|
import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
|
import 'package:didvan/views/widgets/didvan/switch.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:didvan/views/widgets/didvan/text_field.dart';
|
|
import 'package:didvan/views/widgets/hoshan_app_bar.dart';
|
|
import 'package:didvan/views/widgets/marquee_text.dart';
|
|
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
|
|
import 'package:didvan/views/widgets/skeleton_image.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class CreateBotAssistantsPage extends StatefulWidget {
|
|
final int? id;
|
|
const CreateBotAssistantsPage({Key? key, this.id}) : super(key: key);
|
|
|
|
@override
|
|
State<CreateBotAssistantsPage> createState() =>
|
|
_CreateBotAssistantsPageState();
|
|
}
|
|
|
|
class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|
late InputBorder defaultBorder = OutlineInputBorder(
|
|
borderRadius: DesignConfig.mediumBorderRadius,
|
|
borderSide: BorderSide(
|
|
width: 1, color: Theme.of(context).colorScheme.disabledText));
|
|
late List<BotsModel> allBots = context.read<HistoryAiChatState>().bots;
|
|
|
|
final List<String> botModels = ['مدل زبانی', 'مدل تصویری'];
|
|
|
|
// final _formYouTubeKey = GlobalKey<FormState>();
|
|
final _formNameKey = GlobalKey<FormState>();
|
|
final _formPromptKey = GlobalKey<FormState>();
|
|
final _formDescKey = GlobalKey<FormState>();
|
|
|
|
String name = '';
|
|
String prompt = '';
|
|
String desc = '';
|
|
// String? youtubeLink;
|
|
|
|
List<String> countOfLink = [''];
|
|
List<FileCreateAssistantsModel> files = [];
|
|
ValueNotifier<XFile?> image = ValueNotifier(null);
|
|
String selectedBotType = 'text';
|
|
bool isPrivate = true;
|
|
BotAssistants? assistant;
|
|
BotsModel? initialBot;
|
|
Timer? _timer;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
context.read<CreateBotAssistantsState>().getImageToolsBots();
|
|
}
|
|
|
|
void onConfirm(CreateBotAssistantsState state, int selectedBotId) async {
|
|
bool isValid = true;
|
|
// if (!_formYouTubeKey.currentState!.validate()) {
|
|
// isValid = false;
|
|
// }
|
|
if (!_formNameKey.currentState!.validate()) {
|
|
isValid = false;
|
|
}
|
|
|
|
if (!_formDescKey.currentState!.validate()) {
|
|
isValid = false;
|
|
}
|
|
|
|
if (!_formPromptKey.currentState!.validate()) {
|
|
isValid = false;
|
|
}
|
|
if (!isValid) {
|
|
return;
|
|
}
|
|
final List<XFile> resultFiles = [];
|
|
for (var file in files) {
|
|
if (!file.fromNetwork) {
|
|
resultFiles.add(file.file!);
|
|
}
|
|
}
|
|
|
|
final success = await state.createAssistants(
|
|
id: widget.id,
|
|
data: BotAssistantsReqModel(
|
|
type: selectedBotType,
|
|
name: name,
|
|
description: desc,
|
|
botId: selectedBotId,
|
|
prompt: prompt,
|
|
webLinks: countOfLink.first.isEmpty ? null : countOfLink,
|
|
// youtubeLink: youtubeLink,
|
|
isPrivate: isPrivate,
|
|
files: resultFiles,
|
|
deleteImage: assistant != null
|
|
? assistant!.image == null
|
|
: image.value == null,
|
|
image: image.value));
|
|
if (success) {
|
|
context.read<BotAssistantsState>().getMyAssissmant();
|
|
context.read<CreateBotAssistantsState>().assistant = null;
|
|
Navigator.pop(context);
|
|
} else {
|
|
ActionSheetUtils(context).showAlert(AlertData(
|
|
message: 'مشکلی در ارتباط با سرور پیش آمده دوباره تلاش کنید',
|
|
aLertType: ALertType.error));
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
int selectedBotId = selectedBotType == 'text'
|
|
? allBots.first.id!
|
|
: context.read<CreateBotAssistantsState>().imageBots.first.id!;
|
|
|
|
return WillPopScope(
|
|
onWillPop: () async {
|
|
context.read<CreateBotAssistantsState>().assistant = null;
|
|
|
|
return true;
|
|
},
|
|
child: Scaffold(
|
|
appBar: HoshanAppBar(
|
|
onBack: () {
|
|
context.read<CreateBotAssistantsState>().assistant = null;
|
|
Navigator.pop(context);
|
|
},
|
|
withActions: false,
|
|
),
|
|
body: Consumer<CreateBotAssistantsState>(builder: (BuildContext context,
|
|
CreateBotAssistantsState state, Widget? child) {
|
|
if (assistant == null && state.assistant != null) {
|
|
assistant = state.assistant;
|
|
|
|
name = assistant!.name ?? '';
|
|
prompt = assistant!.prompt ?? '';
|
|
desc = assistant!.description ?? '';
|
|
// youtubeLink = assistant!.;
|
|
isPrivate = assistant!.private ?? true;
|
|
if (files.isEmpty &&
|
|
assistant!.files != null &&
|
|
assistant!.files!.isNotEmpty) {
|
|
for (var file in assistant!.files!) {
|
|
files.add(FileCreateAssistantsModel(
|
|
fromNetwork: true, file: null, url: file));
|
|
}
|
|
}
|
|
countOfLink = assistant!.websites ?? [''];
|
|
selectedBotType = assistant!.type ?? 'text';
|
|
|
|
final list = selectedBotType == 'text' ? allBots : state.imageBots;
|
|
for (var bot in list) {
|
|
if (bot.id == assistant!.botId) {
|
|
initialBot = bot;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return state.loading
|
|
? Center(
|
|
child: SpinKitThreeBounce(
|
|
size: 46,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
)
|
|
: SingleChildScrollView(
|
|
physics: const BouncingScrollPhysics(),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 20.0, vertical: 32),
|
|
child: Column(
|
|
children: [
|
|
title(text: 'نوع دستیار'),
|
|
SizedBox(
|
|
width: MediaQuery.sizeOf(context).width,
|
|
child: CustomDropdown<String>(
|
|
closedHeaderPadding: const EdgeInsets.all(12),
|
|
items: botModels,
|
|
enabled: assistant == null,
|
|
initialItem: botModels[0],
|
|
hideSelectedFieldWhenExpanded: false,
|
|
decoration: CustomDropdownDecoration(
|
|
listItemDecoration: ListItemDecoration(
|
|
selectedColor: Theme.of(context)
|
|
.colorScheme
|
|
.surface
|
|
.withOpacity(0.5),
|
|
),
|
|
closedBorder: Border.all(color: Colors.grey),
|
|
closedFillColor:
|
|
Colors.grey.shade100.withOpacity(0.1),
|
|
expandedFillColor:
|
|
Theme.of(context).colorScheme.surface),
|
|
// hintText: "انتخاب کنید",
|
|
onChanged: (value) {
|
|
setState(() {
|
|
final index = botModels.indexOf(value!);
|
|
selectedBotType = index == 0 ? 'text' : 'image';
|
|
});
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
ValueListenableBuilder(
|
|
valueListenable: image,
|
|
builder: (context, img, _) {
|
|
return Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
DidvanButton(
|
|
width: 120,
|
|
style: ButtonStyleMode.flat,
|
|
color: image.value != null ||
|
|
assistant?.image != null
|
|
? Theme.of(context).colorScheme.error
|
|
: null,
|
|
title: image.value != null ||
|
|
assistant?.image != null
|
|
? 'حذف عکس'
|
|
: 'انتخاب عکس',
|
|
onPressed: () async {
|
|
if (image.value != null ||
|
|
assistant?.image != null) {
|
|
if (assistant != null) {
|
|
assistant!.image = null;
|
|
}
|
|
image.value = null;
|
|
return;
|
|
}
|
|
image.value =
|
|
await MediaService.pickImage(
|
|
source: ImageSource.gallery);
|
|
},
|
|
),
|
|
img != null
|
|
? ClipRRect(
|
|
borderRadius:
|
|
DesignConfig.lowBorderRadius,
|
|
child: SizedBox(
|
|
width: 80,
|
|
height: 80,
|
|
child:
|
|
Image.file(File(img.path))),
|
|
)
|
|
: SkeletonImage(
|
|
imageUrl: assistant != null &&
|
|
assistant!.image != null
|
|
? assistant!.image!
|
|
: 'https://via.placeholder.com/70x70',
|
|
width: 80,
|
|
height: 80,
|
|
)
|
|
],
|
|
);
|
|
}),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
title(text: 'انتخاب نام'),
|
|
Form(
|
|
key: _formNameKey,
|
|
child: DidvanTextField(
|
|
initialValue: name,
|
|
onChanged: (value) {
|
|
name = value;
|
|
|
|
if (value.isEmpty) {
|
|
return;
|
|
}
|
|
if (assistant == null) {
|
|
_timer?.cancel();
|
|
_timer =
|
|
Timer(const Duration(seconds: 1), () async {
|
|
await state.getAssistantsName(name: value);
|
|
_formNameKey.currentState!.validate();
|
|
});
|
|
}
|
|
},
|
|
validator: (value) {
|
|
String? result;
|
|
if (value.isEmpty) {
|
|
result = 'نام نباید خالی باشد';
|
|
} else if (value.length < 4) {
|
|
result = 'نام نباید کمتر از 4 حرف باشد';
|
|
} else if (assistant == null &&
|
|
!state.successName) {
|
|
result =
|
|
'اسم دیگری انتخاب کنید این اسم موجود است';
|
|
}
|
|
return result;
|
|
},
|
|
hintText: 'ai@2024_B',
|
|
maxLength: 20,
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
state.loadingName
|
|
? const SizedBox(
|
|
width: 18,
|
|
height: 18,
|
|
child: CircularProgressIndicator())
|
|
: Icon(
|
|
DidvanIcons.info_circle_light,
|
|
color:
|
|
Theme.of(context).colorScheme.caption,
|
|
),
|
|
const SizedBox(width: 4),
|
|
Expanded(
|
|
child: DidvanText(
|
|
state.loadingName
|
|
? '...درحال بررسی اسم'
|
|
: 'نام منحصر به فرد شامل 4 تا 20 کاراکتر (حروف، اعداد، خط تیره، نقطه و زیرخط) ',
|
|
textAlign: TextAlign.right,
|
|
fontSize: 12,
|
|
color: Theme.of(context).colorScheme.caption,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
title(text: 'توضیحات بات'),
|
|
Form(
|
|
key: _formDescKey,
|
|
child: DidvanTextField(
|
|
initialValue: desc,
|
|
// hintText:
|
|
// 'به ربات خود بگویید که چگونه رفتار کند و چگونه به پیامهای کاربر پاسخ دهد. سعی کنید تا حد امکان واضح و مشخص باشید.',
|
|
textInputType: TextInputType.multiline,
|
|
minLine: 4,
|
|
maxLine: 4,
|
|
maxLength: 200,
|
|
hasHeight: false,
|
|
showLen: true,
|
|
onChanged: (value) {
|
|
desc = value;
|
|
},
|
|
validator: (value) {
|
|
String? result;
|
|
if (value.isEmpty) {
|
|
result = 'توضیحات نباید خالی باشد';
|
|
} else if (value.length < 10) {
|
|
result = 'توضیحات نباید کمتر از 10 حرف باشد';
|
|
}
|
|
return result;
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
title(text: 'نوع دستیار'),
|
|
state.loadingImageBots
|
|
? ShimmerPlaceholder(
|
|
width: MediaQuery.sizeOf(context).width,
|
|
height: 48,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
)
|
|
: SizedBox(
|
|
width: MediaQuery.sizeOf(context).width,
|
|
child: CustomDropdown<BotsModel>(
|
|
closedHeaderPadding: const EdgeInsets.all(12),
|
|
items: selectedBotType == 'text'
|
|
? allBots
|
|
: state.imageBots,
|
|
headerBuilder: (context, bot, enabled) =>
|
|
botRow(bot, context),
|
|
listItemBuilder: (context, bot, isSelected,
|
|
onItemSelect) =>
|
|
botRow(bot, context),
|
|
initialItem: assistant != null
|
|
? initialBot
|
|
: (selectedBotType == 'text'
|
|
? allBots
|
|
: state.imageBots)
|
|
.first,
|
|
hideSelectedFieldWhenExpanded: false,
|
|
decoration: CustomDropdownDecoration(
|
|
listItemDecoration: ListItemDecoration(
|
|
selectedColor: Theme.of(context)
|
|
.colorScheme
|
|
.surface
|
|
.withOpacity(0.5),
|
|
),
|
|
closedBorder:
|
|
Border.all(color: Colors.grey),
|
|
closedFillColor:
|
|
Colors.grey.shade100.withOpacity(0.1),
|
|
expandedFillColor: Theme.of(context)
|
|
.colorScheme
|
|
.surface),
|
|
// hintText: "انتخاب کنید",
|
|
onChanged: (value) {
|
|
setState(() {
|
|
selectedBotId = value!.id!;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
title(text: 'دستورالعمل'),
|
|
Form(
|
|
key: _formPromptKey,
|
|
child: DidvanTextField(
|
|
initialValue: prompt,
|
|
hintText:
|
|
'به ربات خود بگویید که چگونه رفتار کند و چگونه به پیامهای کاربر پاسخ دهد. سعی کنید تا حد امکان واضح و مشخص باشید.',
|
|
textInputType: TextInputType.multiline,
|
|
minLine: 6,
|
|
maxLine: 6,
|
|
maxLength: 400,
|
|
hasHeight: false,
|
|
showLen: true,
|
|
onChanged: (value) {
|
|
prompt = value;
|
|
},
|
|
validator: (value) {
|
|
String? result;
|
|
if (value.isEmpty) {
|
|
result = 'دستورالعمل نباید خالی باشد';
|
|
} else if (value.length < 10) {
|
|
result = 'نام نباید کمتر از 10 حرف باشد';
|
|
}
|
|
return result;
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
if (assistant == null)
|
|
Column(
|
|
children: [
|
|
if (selectedBotType == 'text')
|
|
Column(
|
|
children: [
|
|
title(
|
|
text: 'پایگاه دانش', isRequired: false),
|
|
if (files.length != 3)
|
|
SizedBox(
|
|
height: 48,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor:
|
|
Theme.of(context)
|
|
.colorScheme
|
|
.disabledBackground,
|
|
shape:
|
|
const RoundedRectangleBorder(
|
|
borderRadius: DesignConfig
|
|
.lowBorderRadius)),
|
|
onPressed: () async {
|
|
final picks = await MediaService
|
|
.pickMultiFile();
|
|
if (picks != null) {
|
|
for (var file in picks.xFiles) {
|
|
files.add(
|
|
FileCreateAssistantsModel(
|
|
fromNetwork: false,
|
|
file: file,
|
|
url: null));
|
|
}
|
|
}
|
|
state.update();
|
|
},
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
CupertinoIcons.add,
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.caption,
|
|
),
|
|
const SizedBox(
|
|
width: 4,
|
|
),
|
|
DidvanText(
|
|
'آپلود فایل (فایل صوتی، پی دی اف)',
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.caption,
|
|
fontSize: 16,
|
|
)
|
|
],
|
|
)),
|
|
),
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
...List.generate(
|
|
files.length,
|
|
(index) {
|
|
return Stack(
|
|
children: [
|
|
Container(
|
|
width: MediaQuery.sizeOf(
|
|
context)
|
|
.width /
|
|
5,
|
|
height: MediaQuery.sizeOf(
|
|
context)
|
|
.width /
|
|
5,
|
|
margin: const EdgeInsets
|
|
.symmetric(
|
|
horizontal: 8,
|
|
vertical: 12),
|
|
padding: const EdgeInsets
|
|
.all(8),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.disabledBackground,
|
|
borderRadius: DesignConfig
|
|
.lowBorderRadius),
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: files[index]
|
|
.fromNetwork
|
|
? files[index]
|
|
.url!
|
|
.isImage()
|
|
? CachedNetworkImage(
|
|
imageUrl:
|
|
files[index]
|
|
.url!)
|
|
: const Icon(
|
|
CupertinoIcons
|
|
.doc)
|
|
: files[index]
|
|
.file!
|
|
.path
|
|
.isImage()
|
|
? Image.file(
|
|
File(files[
|
|
index]
|
|
.file!
|
|
.path))
|
|
: const Icon(
|
|
CupertinoIcons
|
|
.doc),
|
|
),
|
|
MarqueeText(
|
|
text: files[index]
|
|
.fromNetwork
|
|
? files[index]
|
|
.url!
|
|
.split('/')
|
|
.last
|
|
: files[index]
|
|
.file!
|
|
.name,
|
|
textDirection:
|
|
TextDirection
|
|
.rtl,
|
|
style: Theme.of(
|
|
context)
|
|
.textTheme
|
|
.labelSmall!)
|
|
],
|
|
)),
|
|
Positioned(
|
|
top: 8,
|
|
left: 4,
|
|
child: InkWell(
|
|
onTap: () {
|
|
files.removeAt(index);
|
|
state.update();
|
|
},
|
|
child: Container(
|
|
padding:
|
|
const EdgeInsets
|
|
.all(6),
|
|
decoration:
|
|
BoxDecoration(
|
|
shape: BoxShape
|
|
.circle,
|
|
color: Theme.of(
|
|
context)
|
|
.colorScheme
|
|
.error),
|
|
child: const Icon(
|
|
DidvanIcons
|
|
.trash_solid,
|
|
color: Colors.white,
|
|
size: 18,
|
|
),
|
|
),
|
|
))
|
|
],
|
|
);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
],
|
|
),
|
|
// title(text: 'لینک یوتیوب', isRequired: false),
|
|
// Form(
|
|
// key: _formYouTubeKey,
|
|
// child: DidvanTextField(
|
|
// onChanged: (value) {
|
|
// youtubeLink = value;
|
|
// },
|
|
// validator: (value) =>
|
|
// value.startsWith('https://www.youtube.com') ||
|
|
// value.isEmpty
|
|
// ? null
|
|
// : 'باید لینک یوتیوب باشد',
|
|
// hintText: 'https://www.youtube.com/watch?v',
|
|
// ),
|
|
// ),
|
|
// const SizedBox(
|
|
// height: 24,
|
|
// ),
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
title(
|
|
text: 'لینک وب سایت', isRequired: false),
|
|
Row(
|
|
children: [
|
|
if (countOfLink.length > 1)
|
|
DidvanIconButton(
|
|
icon:
|
|
CupertinoIcons.minus_circle_fill,
|
|
onPressed: () {
|
|
setState(() {
|
|
countOfLink.removeLast();
|
|
});
|
|
},
|
|
),
|
|
if (countOfLink.length != 3)
|
|
DidvanIconButton(
|
|
icon: CupertinoIcons.plus_circle_fill,
|
|
onPressed: () {
|
|
setState(() {
|
|
if (countOfLink.last.isNotEmpty) {
|
|
countOfLink.add('');
|
|
}
|
|
});
|
|
},
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
ListView.builder(
|
|
shrinkWrap: true,
|
|
itemCount: countOfLink.length,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemBuilder: (context, index) => Column(
|
|
children: [
|
|
DidvanTextField(
|
|
onChanged: (value) {
|
|
countOfLink.insert(index, value);
|
|
},
|
|
// validator: (value) {},
|
|
hintText:
|
|
'https://www.weforum.org/agenda/2024/08',
|
|
),
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(
|
|
DidvanIcons.info_circle_light,
|
|
color:
|
|
Theme.of(context).colorScheme.caption,
|
|
),
|
|
const SizedBox(width: 4),
|
|
Expanded(
|
|
child: DidvanText(
|
|
'دستیار شما با استناد بر اطلاعات ارائه شده در پایگاه دانش، پیام کاربران را ارزیابی میکند.',
|
|
textAlign: TextAlign.right,
|
|
fontSize: 12,
|
|
color:
|
|
Theme.of(context).colorScheme.caption,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const DidvanText(
|
|
'نمایش عمومی',
|
|
fontSize: 14,
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: DidvanText(
|
|
'در صورت فعال بودن، دستیار شما توسط سایرین قابل مشاهده بوده و مورد استفاده قرار میگیرد.',
|
|
fontSize: 14,
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.caption,
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 64,
|
|
height: 48,
|
|
child: DidvanSwitch(
|
|
value: !isPrivate,
|
|
title: '',
|
|
onChanged: (value) {
|
|
isPrivate = !value;
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
widget.id != null
|
|
? Flex(
|
|
direction: Axis.horizontal,
|
|
children: [
|
|
Flexible(
|
|
flex: 2,
|
|
child: Stack(
|
|
children: [
|
|
DidvanButton(
|
|
title: state.loadingCreate
|
|
? ' '
|
|
: 'ذخیره تغییرات',
|
|
onPressed: () async =>
|
|
onConfirm(state, selectedBotId),
|
|
),
|
|
if (state.loadingCreate)
|
|
const Positioned.fill(
|
|
child: Center(
|
|
child: SpinKitThreeBounce(
|
|
size: 32,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: 20,
|
|
),
|
|
Flexible(
|
|
flex: 1,
|
|
child: DidvanButton(
|
|
title: 'حذف دستیار',
|
|
style: ButtonStyleMode.flat,
|
|
color:
|
|
Theme.of(context).colorScheme.error,
|
|
onPressed: () {
|
|
ActionSheetUtils(context).openDialog(
|
|
data: ActionSheetData(
|
|
title: 'حذف دستیار',
|
|
titleIcon: DidvanIcons.trash_solid,
|
|
titleColor: Theme.of(context)
|
|
.colorScheme
|
|
.error,
|
|
content: const Column(
|
|
children: [
|
|
DidvanText(
|
|
'با حذف این دستیار، استفاده از آن برای شما و سایر کاربران، امکانپذیر نیست.\nآیا مطمئن هستید؟!',
|
|
fontSize: 14,
|
|
)
|
|
],
|
|
),
|
|
onConfirmed: () async {
|
|
final success =
|
|
await state.deleteAssistants(
|
|
id: widget.id!);
|
|
if (success) {
|
|
context
|
|
.read<BotAssistantsState>()
|
|
.getMyAssissmant();
|
|
|
|
context
|
|
.read<
|
|
CreateBotAssistantsState>()
|
|
.assistant = null;
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
));
|
|
},
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Column(
|
|
children: [
|
|
DidvanButton(
|
|
title:
|
|
state.loadingCreate ? ' ' : 'ذخیره',
|
|
onPressed: () async =>
|
|
onConfirm(state, selectedBotId)),
|
|
if (state.loadingCreate)
|
|
const Positioned.fill(
|
|
child: Center(
|
|
child: SpinKitThreeBounce(
|
|
size: 32,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 24,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
Container botRow(BotsModel bot, BuildContext context) {
|
|
return Container(
|
|
alignment: Alignment.center,
|
|
child: Row(
|
|
children: [
|
|
SkeletonImage(
|
|
imageUrl: bot.image.toString(),
|
|
width: 42,
|
|
height: 42,
|
|
borderRadius: BorderRadius.circular(360),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: DidvanText(
|
|
bot.name.toString(),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
))
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget title({required final String text, final bool isRequired = true}) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
child: Row(
|
|
children: [
|
|
Text.rich(
|
|
TextSpan(
|
|
children: [
|
|
TextSpan(
|
|
text: text,
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
),
|
|
if (isRequired)
|
|
TextSpan(
|
|
text: '*',
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
color: Theme.of(context).colorScheme.error)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|