412 lines
16 KiB
Dart
412 lines
16 KiB
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/ai_chat_args.dart';
|
|
import 'package:didvan/models/ai/bot_assistants_model.dart';
|
|
import 'package:didvan/routes/routes.dart';
|
|
import 'package:didvan/views/ai/bot_assistants_state.dart';
|
|
import 'package:didvan/views/widgets/didvan/button.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:didvan/views/widgets/hoshan_app_bar.dart';
|
|
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
|
|
import 'package:didvan/views/widgets/skeleton_image.dart';
|
|
import 'package:didvan/views/widgets/state_handlers/empty_list.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:persian_number_utility/persian_number_utility.dart';
|
|
|
|
class BotAssistantsPage extends StatefulWidget {
|
|
const BotAssistantsPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<BotAssistantsPage> createState() => _BotAssistantsPageState();
|
|
}
|
|
|
|
class _BotAssistantsPageState extends State<BotAssistantsPage> {
|
|
bool isMyAssistants = true;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: HoshanAppBar(
|
|
onBack: () => Navigator.pop(context),
|
|
withActions: false,
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
|
|
floatingActionButton: isMyAssistants
|
|
? FloatingActionButton.extended(
|
|
label: const DidvanText(
|
|
'ایجاد دستیار جدید',
|
|
color: Colors.white,
|
|
),
|
|
icon: const Icon(
|
|
Icons.add,
|
|
color: Colors.white,
|
|
),
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
onPressed: () {
|
|
Navigator.pushNamed(context, Routes.createBotAssistants);
|
|
},
|
|
)
|
|
: null,
|
|
body: SingleChildScrollView(
|
|
physics: const BouncingScrollPhysics(),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(top: 32, bottom: 24),
|
|
child: DidvanText(
|
|
'انتخاب باتها',
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xff1B3C59),
|
|
),
|
|
),
|
|
),
|
|
switchAssistants(context),
|
|
FutureBuilder<List<BotAssistants>?>(
|
|
future: isMyAssistants
|
|
? BotAssistantsState.getMyAssissmant()
|
|
: BotAssistantsState.getGlobalAssissmant(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasError) {
|
|
return const EmptyList();
|
|
}
|
|
if (!snapshot.hasData) {
|
|
return listOfAssistantsPlaceHolder();
|
|
}
|
|
|
|
return listOfAssistants(list: snapshot.data!);
|
|
}),
|
|
if (isMyAssistants) const SizedBox(height: 72)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
ListView listOfAssistants({required final List<BotAssistants> list}) {
|
|
return ListView.builder(
|
|
itemCount: list.length,
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
itemBuilder: (context, index) {
|
|
final assistants = list[index];
|
|
return Container(
|
|
padding: const EdgeInsets.all(12),
|
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 32),
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white, borderRadius: DesignConfig.lowBorderRadius),
|
|
child: Column(
|
|
children: [
|
|
if (isMyAssistants)
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
decoration: BoxDecoration(
|
|
color:
|
|
Theme.of(context).colorScheme.disabledBackground,
|
|
borderRadius: DesignConfig.lowBorderRadius),
|
|
child: const DidvanText('عمومی'),
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
SkeletonImage(
|
|
imageUrl: assistants.image ?? assistants.bot!.image ?? '',
|
|
width: 80,
|
|
height: 80,
|
|
),
|
|
const SizedBox(
|
|
width: 8,
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
DidvanText(
|
|
assistants.name ?? '',
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
DidvanText(
|
|
assistants.description ?? '',
|
|
fontSize: 12,
|
|
color: Theme.of(context).colorScheme.disabledText,
|
|
),
|
|
const SizedBox(
|
|
height: 18,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
children: [
|
|
const Icon(
|
|
DidvanIcons.calendar_day_light,
|
|
size: 18,
|
|
),
|
|
const SizedBox(
|
|
width: 4,
|
|
),
|
|
DidvanText(
|
|
DateTime.parse(assistants.createdAt!)
|
|
.toPersianDateStr(),
|
|
fontSize: 12,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: isMyAssistants
|
|
? const Row(
|
|
children: [
|
|
Icon(
|
|
DidvanIcons.user_edit_light,
|
|
size: 18,
|
|
),
|
|
SizedBox(
|
|
width: 4,
|
|
),
|
|
DidvanText(
|
|
'ویرایش',
|
|
fontSize: 12,
|
|
),
|
|
],
|
|
)
|
|
: Row(
|
|
children: [
|
|
SkeletonImage(
|
|
imageUrl:
|
|
assistants.user!.photo ?? '',
|
|
width: 24,
|
|
height: 24,
|
|
borderRadius:
|
|
BorderRadius.circular(360),
|
|
),
|
|
const SizedBox(
|
|
width: 4,
|
|
),
|
|
Expanded(
|
|
child: DidvanText(
|
|
assistants.user!.fullName ?? '',
|
|
fontSize: 12,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 12,
|
|
),
|
|
DidvanButton(
|
|
title: 'استفاده از دستیار',
|
|
onPressed: () => Navigator.pushNamed(context, Routes.aiChat,
|
|
arguments: AiChatArgs(
|
|
bot: assistants.bot!.copyWith(
|
|
id: assistants.id, image: assistants.image),
|
|
assistantsName: assistants.name)),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
ListView listOfAssistantsPlaceHolder() {
|
|
return ListView.builder(
|
|
itemCount: 10,
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
itemBuilder: (context, index) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(12),
|
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 32),
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white, borderRadius: DesignConfig.lowBorderRadius),
|
|
child: Column(
|
|
children: [
|
|
if (isMyAssistants)
|
|
const Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
ShimmerPlaceholder(
|
|
width: 60,
|
|
height: 24,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
),
|
|
],
|
|
),
|
|
const Row(
|
|
children: [
|
|
ShimmerPlaceholder(
|
|
width: 80,
|
|
height: 80,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
),
|
|
SizedBox(
|
|
width: 8,
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ShimmerPlaceholder(
|
|
width: 120,
|
|
height: 24,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
),
|
|
SizedBox(
|
|
height: 8,
|
|
),
|
|
ShimmerPlaceholder(
|
|
width: 240,
|
|
height: 46,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
),
|
|
SizedBox(
|
|
height: 18,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: ShimmerPlaceholder(
|
|
height: 18,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
),
|
|
),
|
|
Expanded(child: SizedBox()),
|
|
Expanded(
|
|
child: ShimmerPlaceholder(
|
|
height: 18,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 12,
|
|
),
|
|
ShimmerPlaceholder(
|
|
width: MediaQuery.sizeOf(context).width,
|
|
height: 46,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Container switchAssistants(BuildContext context) {
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 32),
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white, borderRadius: DesignConfig.lowBorderRadius),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: InkWell(
|
|
onTap: () => setState(() => isMyAssistants = true),
|
|
child: Column(
|
|
children: [
|
|
Icon(
|
|
DidvanIcons.profile_solid,
|
|
color: isMyAssistants
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.disabledText,
|
|
),
|
|
Container(
|
|
width: 100,
|
|
height: 1,
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: isMyAssistants
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.disabledText,
|
|
),
|
|
),
|
|
DidvanText(
|
|
'دستیارهای من',
|
|
color: isMyAssistants
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.disabledText,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
height: 34,
|
|
width: 1,
|
|
margin: const EdgeInsets.symmetric(horizontal: 12),
|
|
decoration:
|
|
BoxDecoration(color: Theme.of(context).colorScheme.primary),
|
|
),
|
|
Expanded(
|
|
child: InkWell(
|
|
onTap: () => setState(() => isMyAssistants = false),
|
|
child: Column(
|
|
children: [
|
|
Icon(
|
|
DidvanIcons.profile_solid,
|
|
color: !isMyAssistants
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.disabledText,
|
|
),
|
|
Container(
|
|
width: 100,
|
|
height: 1,
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: !isMyAssistants
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.disabledText,
|
|
),
|
|
),
|
|
DidvanText(
|
|
'دستیارهای دیگران',
|
|
color: !isMyAssistants
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.disabledText,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|