From cd4bf9fb9a1c095065a0e3057493867ef183be37 Mon Sep 17 00:00:00 2001 From: mohsen Date: Thu, 16 Nov 2023 18:06:43 +0330 Subject: [PATCH] fix some bug --- android/app/src/main/AndroidManifest.xml | 2 +- assets/languages/en.json | 3 +- assets/languages/fa.json | 3 +- .../local_db_core/test/widget_test.dart | 10 --- lib/features/main/main_screen.dart | 85 +++++++++++++++++++ lib/features/posts/screen/posts_screen.dart | 6 +- .../posts/widgets/filter_item_widget.dart | 6 +- .../single_post/cubit/single_post_cubit.dart | 4 +- .../screen/single_post_screen.dart | 48 +++++------ .../widget/author_comment_widget.dart | 57 +++++++++++++ 10 files changed, 174 insertions(+), 50 deletions(-) delete mode 100644 data/data_core/local_db/local_db_core/test/widget_test.dart create mode 100644 lib/features/single_post/widget/author_comment_widget.dart diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6236380..eab701c 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - + { body: SafeArea( child: Column( children: [ + Align( + alignment: AlignmentDirectional.centerStart, + child: Padding( + padding: EdgeInsetsDirectional.only( + start: context.width * 24 / AppConstants.instance.appWidth, + top: context.height * 12 / AppConstants.instance.appHeight, + ), + child: GestureDetector( + onTap: _showOptions, + child: SvgPicture.asset('ic_more'.svgPath), + ), + ), + ), Container( margin: EdgeInsets.only( left: context.width * 86 / AppConstants.instance.appWidth, @@ -178,4 +195,72 @@ class _MainScreenState extends State { ), ); } + + void _showOptions() { + showModalBottomSheet( + context: context, + backgroundColor: Colors.transparent, + builder: (context) { + return Container( + height: 120, + width: context.width, + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(color: Colors.white, width: 0.2), + borderRadius: const BorderRadius.only( + topLeft: Radius.circular(16), + topRight: Radius.circular(16), + ), + ), + padding: const EdgeInsets.only( + top: 16, + left: 4, + right: 4, + ), + child: Column( + children: [ + MoreOptionsWidget( + title: Translator.translate('about_us'), + onTap: () { + Navigator.pop(context); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return const AboutUsScreen(); + }, + ), + ); + }, + ), + const SizedBox(height: 8), + Container( + width: context.width, + height: 1, + color: const Color(0xffD3D8E9), + ), + const SizedBox(height: 8), + MoreOptionsWidget( + title: Translator.translate('select_language'), + onTap: () { + Navigator.pop(context); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return BlocProvider( + child: const SelectLanguageScreen(), + create: (context) => SelectLanguageCubit(), + ); + }, + ), + ); + }, + ), + ], + ), + ); + }, + ); + } } diff --git a/lib/features/posts/screen/posts_screen.dart b/lib/features/posts/screen/posts_screen.dart index 10839d5..70a4d1e 100644 --- a/lib/features/posts/screen/posts_screen.dart +++ b/lib/features/posts/screen/posts_screen.dart @@ -105,7 +105,7 @@ class _PostsScreenState extends State { forceElevated: false, shadowColor: Colors.transparent, bottom: PreferredSize( - preferredSize: const Size.fromHeight(116), + preferredSize: const Size.fromHeight(100), child: Column( children: [ SizedBox(height: context.height * 26 / AppConstants.instance.appHeight), @@ -239,7 +239,7 @@ class _PostsScreenState extends State { ], ), ), - SizedBox(height: context.height * 35 / AppConstants.instance.appHeight), + SizedBox(height: context.height * 12 / AppConstants.instance.appHeight), if (widget.showFilters) SizedBox( height: context.height * 31 / AppConstants.instance.appHeight, @@ -262,7 +262,7 @@ class _PostsScreenState extends State { scrollDirection: Axis.horizontal, ), ), - SizedBox(height: context.height * 26 / AppConstants.instance.appHeight), + SizedBox(height: context.height * 12 / AppConstants.instance.appHeight), ], ), ), diff --git a/lib/features/posts/widgets/filter_item_widget.dart b/lib/features/posts/widgets/filter_item_widget.dart index 7a5d8cc..94c8528 100644 --- a/lib/features/posts/widgets/filter_item_widget.dart +++ b/lib/features/posts/widgets/filter_item_widget.dart @@ -16,8 +16,8 @@ class FilterItemWidget extends StatelessWidget { Widget build(BuildContext context) { return Container( padding: EdgeInsets.only( - left: context.width * 9 / AppConstants.instance.appWidth, - right: context.width * 9 / AppConstants.instance.appWidth, + left: context.width * 20 / AppConstants.instance.appWidth, + right: context.width * 20 / AppConstants.instance.appWidth, top: context.height * 5 / AppConstants.instance.appHeight, bottom: context.height * 5 / AppConstants.instance.appHeight, ), @@ -30,7 +30,7 @@ class FilterItemWidget extends StatelessWidget { title, style: TextStyle( color: selected ? const Color(0xffffffff) : const Color(0xff636E88), - fontSize: 12, + fontSize: 14, ), ), ); diff --git a/lib/features/single_post/cubit/single_post_cubit.dart b/lib/features/single_post/cubit/single_post_cubit.dart index d47d505..a3e8f10 100644 --- a/lib/features/single_post/cubit/single_post_cubit.dart +++ b/lib/features/single_post/cubit/single_post_cubit.dart @@ -18,11 +18,11 @@ class SinglePostCubit extends Cubit> { void empty() => emit(BaseCubitType(eventName: SinglePostState.empty)); - void addComment(String comment) { + void addComment(String comment, String author) { Comment newComment = Comment( date: DateTime.now().millisecondsSinceEpoch, text: comment, - author: 'محسن زمانی', + author: author, id: Random.secure().nextInt(10000), ); commentList.insert(0, newComment); diff --git a/lib/features/single_post/screen/single_post_screen.dart b/lib/features/single_post/screen/single_post_screen.dart index faac3b9..e7358de 100644 --- a/lib/features/single_post/screen/single_post_screen.dart +++ b/lib/features/single_post/screen/single_post_screen.dart @@ -4,11 +4,11 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:sonnat/core/extensions/context_extension.dart'; import 'package:sonnat/core/extensions/string_extension.dart'; import 'package:sonnat/core/html/html_viewer.dart'; -import 'package:sonnat/core/language/translator.dart'; import 'package:sonnat/core/utils/app_constants.dart'; import 'package:sonnat/core/utils/base_cubit_type.dart'; import 'package:sonnat/features/single_post/cubit/single_post_cubit.dart'; import 'package:sonnat/features/single_post/widget/add_comment_widget.dart'; +import 'package:sonnat/features/single_post/widget/author_comment_widget.dart'; import 'package:sonnat/features/single_post/widget/post_comment_widget.dart'; class SinglePostScreen extends StatefulWidget { @@ -22,6 +22,7 @@ class SinglePostScreen extends StatefulWidget { class _SinglePostScreenState extends State { late final SinglePostCubit _cubit; + final TextEditingController _fullNameController = TextEditingController(); bool _loading = true; @override @@ -42,6 +43,8 @@ class _SinglePostScreenState extends State { break; case SinglePostState.data: _loading = false; + _fullNameController.text = ''; + _cubit.empty(); break; case SinglePostState.loading: _loading = true; @@ -53,7 +56,7 @@ class _SinglePostScreenState extends State { if (_loading) { return const Center(child: CircularProgressIndicator()); } - if(_cubit.model == null) { + if (_cubit.model == null) { return const Center(child: Text('خطا در دریافت اطلاعات')); } String? thumbnail = _cubit.model!.thumbnail; @@ -134,7 +137,7 @@ class _SinglePostScreenState extends State { ), const Spacer(), Text( - _cubit.commentList.length.toString(), + _cubit.model!.commentCount.toString(), style: const TextStyle( color: Colors.white, fontSize: 17, @@ -145,9 +148,9 @@ class _SinglePostScreenState extends State { child: SvgPicture.asset('ic_comment'.svgPath), ), const SizedBox(width: 21), - const Text( - '29', - style: TextStyle( + Text( + _cubit.model!.viewCount.toString(), + style: const TextStyle( color: Colors.white, fontSize: 17, ), @@ -204,7 +207,9 @@ class _SinglePostScreenState extends State { color: const Color(0xffD3D8E9), ), const SizedBox(height: 30), - AddCommentWidget(sendComment: _cubit.addComment), + AuthorCommentWidget(controller: _fullNameController), + const SizedBox(height: 30), + AddCommentWidget(sendComment: _sendComment), if (_cubit.commentList.isEmpty) const SizedBox(height: 30), const SizedBox(height: 8), ListView.builder( @@ -215,28 +220,6 @@ class _SinglePostScreenState extends State { }, itemCount: _cubit.commentList.length, ), - if (_cubit.commentList.isNotEmpty) - Padding( - padding: const EdgeInsets.only(top: 15, bottom: 30), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - Translator.translate('show_all_comments'), - style: const TextStyle( - fontSize: 10, - color: Color(0xff404966), - ), - ), - const SizedBox(width: 4), - SvgPicture.asset( - 'ic_arrow_down'.svgPath, - width: 8, - height: 5, - ), - ], - ), - ), ], ), ), @@ -248,4 +231,11 @@ class _SinglePostScreenState extends State { ), ); } + + void _sendComment(String comment) { + if (_fullNameController.text.trim().isEmpty) { + return; + } + _cubit.addComment(comment, _fullNameController.text.trim()); + } } diff --git a/lib/features/single_post/widget/author_comment_widget.dart b/lib/features/single_post/widget/author_comment_widget.dart new file mode 100644 index 0000000..712637f --- /dev/null +++ b/lib/features/single_post/widget/author_comment_widget.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:sonnat/core/extensions/context_extension.dart'; +import 'package:sonnat/core/language/translator.dart'; +import 'package:sonnat/core/utils/app_constants.dart'; + +class AuthorCommentWidget extends StatefulWidget { + final TextEditingController controller; + + const AuthorCommentWidget({super.key, required this.controller}); + + @override + State createState() => _AuthorCommentWidgetState(); +} + +class _AuthorCommentWidgetState extends State { + + + @override + Widget build(BuildContext context) { + return SizedBox( + height: 49 * context.height / AppConstants.instance.appHeight, + child: TextFormField( + autofocus: false, + maxLength: 300, + controller: widget.controller, + maxLines: 10, + minLines: 4, + style: const TextStyle( + color: Color(0xff8D95AB), + fontSize: 10, + ), + decoration: InputDecoration( + fillColor: Colors.transparent, + contentPadding: const EdgeInsets.symmetric( + vertical: 15, + horizontal: 18, + ), + hintText: Translator.translate('full_name'), + filled: true, + counterText: '', + hintStyle: const TextStyle( + color: Color(0xff8D95AB), + fontSize: 10, + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(19), + borderSide: const BorderSide(color: Color(0xff636E88)), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(19), + borderSide: const BorderSide(color: Color(0xff636E88)), + ), + ), + ), + ); + } +}