From b0d6566ac33a6c8d648526ed84b5d7712bc4ad70 Mon Sep 17 00:00:00 2001 From: OkaykOrhmn Date: Mon, 25 Nov 2024 15:16:47 +0330 Subject: [PATCH] "Updated various files in the lib/views directory, including route_generator, ai_chat_page, create_bot_assistants_page, and others, with changes to UI, layout, and functionality." --- lib/routes/route_generator.dart | 2 + lib/views/ai/ai_chat_page.dart | 9 ++- lib/views/ai/create_bot_assistants_page.dart | 10 +-- lib/views/ai/create_bot_assistants_state.dart | 3 +- lib/views/ai/info_page.dart | 73 ++++++++++--------- lib/views/ai/tool_screen.dart | 4 +- lib/views/ai/tools_screen.dart | 45 +++++++++--- lib/views/ai/widgets/ai_message_bar.dart | 31 +++++--- lib/views/ai/widgets/hoshan_drawer.dart | 6 +- lib/views/home/home.dart | 4 +- lib/views/profile/profile.dart | 2 +- lib/views/widgets/hoshan_app_bar.dart | 6 +- lib/views/widgets/skeleton_image.dart | 4 + pubspec.yaml | 2 +- 14 files changed, 127 insertions(+), 74 deletions(-) diff --git a/lib/routes/route_generator.dart b/lib/routes/route_generator.dart index 9b368b3..9846adc 100644 --- a/lib/routes/route_generator.dart +++ b/lib/routes/route_generator.dart @@ -330,6 +330,8 @@ class RouteGenerator { final id = settings.arguments as int?; if (id != null) { pr.getAnAssistant(id: id); + } else { + pr.getImageToolsBots(); } return pr; }, diff --git a/lib/views/ai/ai_chat_page.dart b/lib/views/ai/ai_chat_page.dart index 727d2c1..9c83094 100644 --- a/lib/views/ai/ai_chat_page.dart +++ b/lib/views/ai/ai_chat_page.dart @@ -111,7 +111,9 @@ class _AiChatPageState extends State { ), key: scaffKey, resizeToAvoidBottomInset: true, - drawer: const HoshanDrawer(), + drawer: HoshanDrawer( + scaffKey: scaffKey, + ), body: state.loading ? Center( child: Image.asset( @@ -166,7 +168,10 @@ class _AiChatPageState extends State { .caption, textAlign: TextAlign.justify, )), - ) + ), + const SizedBox( + height: 100, + ), ], ) ], diff --git a/lib/views/ai/create_bot_assistants_page.dart b/lib/views/ai/create_bot_assistants_page.dart index 8f42a7c..6b49e1a 100644 --- a/lib/views/ai/create_bot_assistants_page.dart +++ b/lib/views/ai/create_bot_assistants_page.dart @@ -335,9 +335,9 @@ class _CreateBotAssistantsPageState extends State { hintText: 'توضیح دهید چه کارهایی از این ربات بر می‌آید.', textInputType: TextInputType.multiline, - minLine: 4, - maxLine: 4, - maxLength: 800, + minLine: 6, + maxLine: 6, + maxLength: 1000, hasHeight: false, showLen: true, onChanged: (value) { @@ -357,7 +357,7 @@ class _CreateBotAssistantsPageState extends State { const SizedBox( height: 24, ), - title(text: 'نوع دستیار'), + title(text: 'انتخاب مدل'), state.loadingImageBots ? ShimmerPlaceholder( width: MediaQuery.sizeOf(context).width, @@ -414,7 +414,7 @@ class _CreateBotAssistantsPageState extends State { hintText: 'به ربات خود بگویید که چگونه رفتار کند و چگونه به پیام‌های کاربر پاسخ دهد. سعی کنید تا حد امکان پیام واضح و مشخص باشد.', textInputType: TextInputType.multiline, - minLine: 6, + minLine: 10, maxLine: 10, // maxLength: 2000, hasHeight: false, diff --git a/lib/views/ai/create_bot_assistants_state.dart b/lib/views/ai/create_bot_assistants_state.dart index 42d1e86..c71511f 100644 --- a/lib/views/ai/create_bot_assistants_state.dart +++ b/lib/views/ai/create_bot_assistants_state.dart @@ -89,9 +89,10 @@ class CreateBotAssistantsState extends CoreProvier { } Future getAnAssistant({required final int id}) async { + await getImageToolsBots(); + loading = true; update(); - await getImageToolsBots(); final service = RequestService( RequestHelper.getAssistant(id), ); diff --git a/lib/views/ai/info_page.dart b/lib/views/ai/info_page.dart index 254e55c..09f8bdb 100644 --- a/lib/views/ai/info_page.dart +++ b/lib/views/ai/info_page.dart @@ -29,6 +29,7 @@ class _InfoPageState extends State { return Scaffold( appBar: HoshanAppBar( withActions: false, + withInfo: false, onBack: () => Navigator.pop(context), ), body: Consumer(builder: (context, state, child) { @@ -53,17 +54,18 @@ class _InfoPageState extends State { physics: const BouncingScrollPhysics(), child: Column( children: [ - Center( - child: Padding( - padding: const EdgeInsets.only(top: 32, bottom: 24), - child: DidvanText( - state.infoModel.title ?? 'آموزش پرامپت نویسی اصولی', - fontSize: 20, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.checkFav, + if (state.infoModel.title != null) + Center( + child: Padding( + padding: const EdgeInsets.only(top: 32, bottom: 24), + child: DidvanText( + state.infoModel.title!, + fontSize: 20, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.checkFav, + ), ), ), - ), if (state.infoModel.url != null) Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), @@ -76,6 +78,34 @@ class _InfoPageState extends State { ), ), ), + if (state.infoModel.url != null) + Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Row( + children: [ + DidvanText( + 'آنچه در این ویدیو خواهید دید:', + fontSize: 16, + ), + ], + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: + state.infoModel.description!.length, + itemBuilder: (context, index) => summery( + state.infoModel.description?[index] ?? + ''), + )) + ], + ), + ), if (state.infoModel.pdf != null) Padding( padding: const EdgeInsets.fromLTRB(20, 20, 20, 0), @@ -87,31 +117,6 @@ class _InfoPageState extends State { }, ), ), - Padding( - padding: const EdgeInsets.all(20.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Row( - children: [ - DidvanText( - 'آنچه در این ویدیو خواهید دید:', - fontSize: 16, - ), - ], - ), - Padding( - padding: const EdgeInsets.all(8.0), - child: ListView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemCount: state.infoModel.description!.length, - itemBuilder: (context, index) => summery( - state.infoModel.description?[index] ?? ''), - )) - ], - ), - ), ], ), ), diff --git a/lib/views/ai/tool_screen.dart b/lib/views/ai/tool_screen.dart index 2fd99bb..95c547e 100644 --- a/lib/views/ai/tool_screen.dart +++ b/lib/views/ai/tool_screen.dart @@ -87,10 +87,12 @@ class _ToolScreenState extends State { height: 4, ), DidvanText( - bot.name!, + bot.name ?? '', fontSize: 16, fontWeight: FontWeight.bold, color: Theme.of(context).colorScheme.text, + maxLines: 1, + overflow: TextOverflow.ellipsis, ), if (bot.short != null) Column( diff --git a/lib/views/ai/tools_screen.dart b/lib/views/ai/tools_screen.dart index 56f43bc..ba5c7a5 100644 --- a/lib/views/ai/tools_screen.dart +++ b/lib/views/ai/tools_screen.dart @@ -5,6 +5,7 @@ import 'package:didvan/views/ai/ai_state.dart'; import 'package:didvan/views/ai/tools_state.dart'; import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:didvan/views/widgets/shimmer_placeholder.dart'; +import 'package:didvan/views/widgets/state_handlers/empty_connection.dart'; import 'package:didvan/views/widgets/state_handlers/empty_state.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -54,9 +55,22 @@ class _ToolsScreenState extends State { if (state.loading) { return toolsPlaceHolder(); } + if (tools == null) { + return Padding( + padding: EdgeInsets.only( + top: MediaQuery.sizeOf(context).height * 0.1), + child: Center( + child: EmptyConnection( + onRetry: () { + context.read().getTools(); + }, + ), + ), + ); + } return ListView.builder( - itemCount: tools!.length, + itemCount: tools.length, shrinkWrap: true, padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 24) .copyWith(bottom: 46), @@ -94,10 +108,14 @@ class _ToolsScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - DidvanText( - tool.name!, - fontSize: 16, - fontWeight: FontWeight.bold, + Expanded( + child: DidvanText( + tool.name ?? '', + fontSize: 16, + fontWeight: FontWeight.bold, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), ), Container( padding: const EdgeInsets.symmetric( @@ -119,17 +137,22 @@ class _ToolsScreenState extends State { ), DidvanText( '${tool.bots!.map( - (e) => e.name!, - )}' + (e) => e.name!, + ).take(3)}' .replaceAll('(', '') .replaceAll(')', ''), fontSize: 12, color: Theme.of(context).colorScheme.primary, + maxLines: 1, + overflow: TextOverflow.ellipsis, ), - DidvanText(tool.description!, - fontSize: 12, - color: - Theme.of(context).colorScheme.caption) + DidvanText( + tool.description ?? '', + fontSize: 12, + overflow: TextOverflow.ellipsis, + color: Theme.of(context).colorScheme.caption, + maxLines: 2, + ) ], ), ) diff --git a/lib/views/ai/widgets/ai_message_bar.dart b/lib/views/ai/widgets/ai_message_bar.dart index 8891eef..67363d3 100644 --- a/lib/views/ai/widgets/ai_message_bar.dart +++ b/lib/views/ai/widgets/ai_message_bar.dart @@ -310,11 +310,12 @@ class _AiMessageBarState extends State { }); } - Row recorderAndTextMessageHandler(BuildContext context, AiChatState state) { - return Row( - crossAxisAlignment: CrossAxisAlignment.end, - children: _mRecorder!.isPaused - ? [ + Widget recorderAndTextMessageHandler( + BuildContext context, AiChatState state) { + return _mRecorder!.isPaused + ? Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ Expanded( child: Row( mainAxisAlignment: MainAxisAlignment.center, @@ -345,9 +346,12 @@ class _AiMessageBarState extends State { }); }, ) - ] - : _mRecorder!.isRecording - ? [ + ], + ) + : _mRecorder!.isRecording + ? Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ Expanded( child: Row( mainAxisAlignment: MainAxisAlignment.center, @@ -372,8 +376,11 @@ class _AiMessageBarState extends State { }); }, ) - ] - : [ + ], + ) + : Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ Expanded( child: state.file != null && state.file!.isRecorded ? audioContainer() @@ -417,7 +424,7 @@ class _AiMessageBarState extends State { ]), ) ], - ); + ); } TextFormField edittext(BuildContext context, AiChatState state) { @@ -446,7 +453,7 @@ class _AiMessageBarState extends State { }, child: const Icon(DidvanIcons.close_circle_solid), ) - : const SizedBox(), + : null, ), ); } diff --git a/lib/views/ai/widgets/hoshan_drawer.dart b/lib/views/ai/widgets/hoshan_drawer.dart index d98db07..8f0ea94 100644 --- a/lib/views/ai/widgets/hoshan_drawer.dart +++ b/lib/views/ai/widgets/hoshan_drawer.dart @@ -9,7 +9,6 @@ import 'package:didvan/models/view/alert_data.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/divider.dart'; import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:didvan/views/widgets/shimmer_placeholder.dart'; @@ -20,7 +19,8 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class HoshanDrawer extends StatefulWidget { - const HoshanDrawer({Key? key}) : super(key: key); + final GlobalKey? scaffKey; + const HoshanDrawer({Key? key, this.scaffKey}) : super(key: key); @override State createState() => _HoshanDrawerState(); @@ -48,7 +48,7 @@ class _HoshanDrawerState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ InkWell( - onTap: () => homeScaffKey.currentState!.closeDrawer(), + onTap: () => widget.scaffKey?.currentState?.closeDrawer(), child: const Icon( DidvanIcons.close_regular, ), diff --git a/lib/views/home/home.dart b/lib/views/home/home.dart index 7f65681..e810a4c 100644 --- a/lib/views/home/home.dart +++ b/lib/views/home/home.dart @@ -189,7 +189,9 @@ class _HomeState extends State appBar: getAppBar(), resizeToAvoidBottomInset: false, drawer: context.watch().tabController.index == 2 - ? const HoshanDrawer() + ? HoshanDrawer( + scaffKey: homeScaffKey, + ) : null, body: WillPopScope( onWillPop: () async { diff --git a/lib/views/profile/profile.dart b/lib/views/profile/profile.dart index 37125f6..54ac391 100644 --- a/lib/views/profile/profile.dart +++ b/lib/views/profile/profile.dart @@ -348,7 +348,7 @@ class _ProfilePageState extends State { ), const SizedBox(height: 16), DidvanText( - 'نسخه نرم‌افزار: 3.3.6', + 'نسخه نرم‌افزار: 3.3.7', style: Theme.of(context).textTheme.bodySmall, ), ], diff --git a/lib/views/widgets/hoshan_app_bar.dart b/lib/views/widgets/hoshan_app_bar.dart index 121bfe0..7ed0fcd 100644 --- a/lib/views/widgets/hoshan_app_bar.dart +++ b/lib/views/widgets/hoshan_app_bar.dart @@ -15,8 +15,10 @@ import 'package:provider/provider.dart'; class HoshanAppBar extends StatelessWidget implements PreferredSizeWidget { final Function()? onBack; + final bool withInfo; final bool withActions; - const HoshanAppBar({Key? key, this.onBack, this.withActions = true}) + const HoshanAppBar( + {Key? key, this.onBack, this.withActions = true, this.withInfo = true}) : super(key: key); @override @@ -57,7 +59,7 @@ class HoshanAppBar extends StatelessWidget implements PreferredSizeWidget { ), Row( children: [ - if (withActions) + if (withInfo) DidvanIconButton( icon: DidvanIcons.info_circle_light, size: 32, diff --git a/lib/views/widgets/skeleton_image.dart b/lib/views/widgets/skeleton_image.dart index accb399..ef8c323 100644 --- a/lib/views/widgets/skeleton_image.dart +++ b/lib/views/widgets/skeleton_image.dart @@ -4,6 +4,7 @@ import 'package:didvan/config/theme_data.dart'; import 'package:didvan/services/network/request.dart'; import 'package:didvan/services/network/request_helper.dart'; import 'package:didvan/views/widgets/shimmer_placeholder.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; // ignore: depend_on_referenced_packages import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart'; @@ -34,6 +35,9 @@ class SkeletonImage extends StatelessWidget { borderRadius: borderRadius ?? BorderRadius.zero, child: CachedNetworkImage( errorWidget: (context, url, error) { + if (kDebugMode) { + print('image fetch compelete with Error: $error'); + } return Container( decoration: BoxDecoration( color: Theme.of(context).colorScheme.disabledBackground), diff --git a/pubspec.yaml b/pubspec.yaml index 08aa5eb..2f7d2d7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 3.3.6+3360 +version: 3.3.7+3370 environment: sdk: ">=2.19.0 <3.0.0"