Browse Source

fix some bug

master
mohsen 1 year ago
parent
commit
cd4bf9fb9a
  1. 2
      android/app/src/main/AndroidManifest.xml
  2. 3
      assets/languages/en.json
  3. 3
      assets/languages/fa.json
  4. 10
      data/data_core/local_db/local_db_core/test/widget_test.dart
  5. 85
      lib/features/main/main_screen.dart
  6. 6
      lib/features/posts/screen/posts_screen.dart
  7. 6
      lib/features/posts/widgets/filter_item_widget.dart
  8. 4
      lib/features/single_post/cubit/single_post_cubit.dart
  9. 46
      lib/features/single_post/screen/single_post_screen.dart
  10. 57
      lib/features/single_post/widget/author_comment_widget.dart

2
android/app/src/main/AndroidManifest.xml

@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="${applicationName}"
android:icon="@mipmap/launcher_icon"

3
assets/languages/en.json

@ -18,5 +18,6 @@
"select_language": "Select language",
"send": "Send",
"show_all_comments": "View all comments",
"search": "Search"
"search": "Search",
"full_name": "Full name"
}

3
assets/languages/fa.json

@ -18,5 +18,6 @@
"send": "ارسال",
"write_comment": "دیدگاه خود را وارد کنید",
"show_all_comments": "مشاهده همه دیدگاه ها",
"search": "جستجو"
"search": "جستجو",
"full_name": "نام کامل"
}

10
data/data_core/local_db/local_db_core/test/widget_test.dart

@ -1,10 +0,0 @@
import 'package:flutter_test/flutter_test.dart';
void main() {
test('adds one to input values', () {
// final calculator = Calculator();
// expect(calculator.addOne(2), 3);
// expect(calculator.addOne(-7), -6);
// expect(calculator.addOne(0), 1);
});
}

85
lib/features/main/main_screen.dart

@ -4,7 +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/language/translator.dart';
import 'package:sonnat/core/select_language/cubit/select_language_cubit.dart';
import 'package:sonnat/core/select_language/screen/select_language_screen.dart';
import 'package:sonnat/core/utils/app_constants.dart';
import 'package:sonnat/core/widgets/more_options_widget.dart';
import 'package:sonnat/features/about_us/about_us_screen.dart';
import 'package:sonnat/features/main/widget/main_item_widget.dart';
import 'package:sonnat/features/posts/cubit/posts_cubit.dart';
import 'package:sonnat/features/posts/screen/posts_screen.dart';
@ -41,6 +45,19 @@ class _MainScreenState extends State<MainScreen> {
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<MainScreen> {
),
);
}
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(),
);
},
),
);
},
),
],
),
);
},
);
}
}

6
lib/features/posts/screen/posts_screen.dart

@ -105,7 +105,7 @@ class _PostsScreenState extends State<PostsScreen> {
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<PostsScreen> {
],
),
),
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<PostsScreen> {
scrollDirection: Axis.horizontal,
),
),
SizedBox(height: context.height * 26 / AppConstants.instance.appHeight),
SizedBox(height: context.height * 12 / AppConstants.instance.appHeight),
],
),
),

6
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,
),
),
);

4
lib/features/single_post/cubit/single_post_cubit.dart

@ -18,11 +18,11 @@ class SinglePostCubit extends Cubit<BaseCubitType<SinglePostState>> {
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);

46
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<SinglePostScreen> {
late final SinglePostCubit _cubit;
final TextEditingController _fullNameController = TextEditingController();
bool _loading = true;
@override
@ -42,6 +43,8 @@ class _SinglePostScreenState extends State<SinglePostScreen> {
break;
case SinglePostState.data:
_loading = false;
_fullNameController.text = '';
_cubit.empty();
break;
case SinglePostState.loading:
_loading = true;
@ -134,7 +137,7 @@ class _SinglePostScreenState extends State<SinglePostScreen> {
),
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<SinglePostScreen> {
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<SinglePostScreen> {
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<SinglePostScreen> {
},
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<SinglePostScreen> {
),
);
}
void _sendComment(String comment) {
if (_fullNameController.text.trim().isEmpty) {
return;
}
_cubit.addComment(comment, _fullNameController.text.trim());
}
}

57
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<AuthorCommentWidget> createState() => _AuthorCommentWidgetState();
}
class _AuthorCommentWidgetState extends State<AuthorCommentWidget> {
@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)),
),
),
),
);
}
}
Loading…
Cancel
Save