Sonnat Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
10 KiB

1 year ago
1 year ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_bloc/flutter_bloc.dart';
  3. import 'package:flutter_svg/flutter_svg.dart';
  4. import 'package:sonnat/core/extensions/context_extension.dart';
  5. import 'package:sonnat/core/extensions/string_extension.dart';
  6. import 'package:sonnat/core/html/html_viewer.dart';
  7. import 'package:sonnat/core/language/translator.dart';
  8. import 'package:sonnat/core/utils/app_constants.dart';
  9. import 'package:sonnat/core/utils/base_cubit_type.dart';
  10. import 'package:sonnat/features/single_post/cubit/single_post_cubit.dart';
  11. import 'package:sonnat/features/single_post/widget/add_comment_widget.dart';
  12. import 'package:sonnat/features/single_post/widget/post_comment_widget.dart';
  13. class SinglePostScreen extends StatefulWidget {
  14. final int postId;
  15. const SinglePostScreen({super.key, required this.postId});
  16. @override
  17. State<SinglePostScreen> createState() => _SinglePostScreenState();
  18. }
  19. class _SinglePostScreenState extends State<SinglePostScreen> {
  20. late final SinglePostCubit _cubit;
  21. bool _loading = true;
  22. @override
  23. void initState() {
  24. _cubit = BlocProvider.of<SinglePostCubit>(context);
  25. _cubit.getSinglePostData(postId: widget.postId);
  26. super.initState();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return Scaffold(
  31. body: SafeArea(
  32. child: BlocBuilder<SinglePostCubit, BaseCubitType<SinglePostState>>(
  33. builder: (context, state) {
  34. switch (state.eventName!) {
  35. case SinglePostState.empty:
  36. break;
  37. case SinglePostState.data:
  38. _loading = false;
  39. break;
  40. case SinglePostState.loading:
  41. _loading = true;
  42. break;
  43. case SinglePostState.error:
  44. _loading = false;
  45. break;
  46. }
  47. if (_loading) {
  48. return const Center(child: CircularProgressIndicator());
  49. }
  50. if(_cubit.model == null) {
  51. return const Center(child: Text('خطا در دریافت اطلاعات'));
  52. }
  53. String? thumbnail = _cubit.model!.thumbnail;
  54. return SingleChildScrollView(
  55. child: Column(
  56. children: [
  57. SizedBox(
  58. height: 304,
  59. child: Stack(
  60. fit: StackFit.expand,
  61. children: [
  62. thumbnail == null
  63. ? Center(
  64. child: Icon(
  65. Icons.image_search,
  66. color: Colors.grey.withOpacity(0.5),
  67. size: 150,
  68. ),
  69. )
  70. : Image.network(
  71. thumbnail,
  72. fit: BoxFit.cover,
  73. errorBuilder: (context, error, stackTrace) {
  74. return Center(
  75. child: Icon(
  76. Icons.image_search,
  77. color: Colors.grey.withOpacity(0.5),
  78. size: 150,
  79. ),
  80. );
  81. },
  82. ),
  83. PositionedDirectional(
  84. end: 16,
  85. top: 16,
  86. child: GestureDetector(
  87. onTap: () {
  88. Navigator.pop(context);
  89. },
  90. child: const Icon(
  91. Icons.arrow_forward_rounded,
  92. color: Colors.white,
  93. ),
  94. ),
  95. ),
  96. Positioned(
  97. bottom: 0,
  98. left: 0,
  99. right: 0,
  100. child: Container(
  101. height: 150,
  102. width: 1,
  103. decoration: BoxDecoration(
  104. gradient: LinearGradient(
  105. begin: Alignment.bottomCenter,
  106. end: Alignment.topCenter,
  107. colors: [
  108. Colors.black.withOpacity(0.7),
  109. Colors.black.withOpacity(0),
  110. ],
  111. ),
  112. ),
  113. ),
  114. ),
  115. Padding(
  116. padding: EdgeInsetsDirectional.only(
  117. start: context.width * 26 / AppConstants.instance.appWidth,
  118. end: context.width * 37 / AppConstants.instance.appWidth,
  119. bottom: 18,
  120. ),
  121. child: Align(
  122. alignment: Alignment.bottomCenter,
  123. child: Row(
  124. children: [
  125. Padding(
  126. padding: const EdgeInsets.all(8),
  127. child: SvgPicture.asset('ic_share'.svgPath),
  128. ),
  129. const Spacer(),
  130. Text(
  131. _cubit.commentList.length.toString(),
  132. style: const TextStyle(
  133. color: Colors.white,
  134. fontSize: 17,
  135. ),
  136. ),
  137. Padding(
  138. padding: const EdgeInsets.all(8),
  139. child: SvgPicture.asset('ic_comment'.svgPath),
  140. ),
  141. const SizedBox(width: 21),
  142. const Text(
  143. '29',
  144. style: TextStyle(
  145. color: Colors.white,
  146. fontSize: 17,
  147. ),
  148. ),
  149. Padding(
  150. padding: const EdgeInsets.all(8),
  151. child: SvgPicture.asset('ic_view'.svgPath),
  152. ),
  153. ],
  154. ),
  155. ),
  156. ),
  157. const Padding(
  158. padding: EdgeInsets.all(8),
  159. child: Align(
  160. alignment: Alignment.bottomCenter,
  161. child: Row(
  162. mainAxisAlignment: MainAxisAlignment.end,
  163. children: [],
  164. ),
  165. ),
  166. ),
  167. ],
  168. ),
  169. ),
  170. Padding(
  171. padding: EdgeInsetsDirectional.only(
  172. start: context.width * 26 / AppConstants.instance.appWidth,
  173. end: context.width * 37 / AppConstants.instance.appWidth,
  174. top: 16,
  175. ),
  176. child: Column(
  177. crossAxisAlignment: CrossAxisAlignment.start,
  178. children: [
  179. Text(
  180. _cubit.model!.title,
  181. style: const TextStyle(
  182. fontWeight: FontWeight.bold,
  183. fontSize: 16,
  184. ),
  185. ),
  186. Text(
  187. _cubit.model!.publishDate,
  188. style: const TextStyle(fontSize: 11),
  189. ),
  190. HTMLViewer(
  191. htmlContent: _cubit.model!.content,
  192. fontSizeFactor: 1,
  193. ),
  194. const SizedBox(height: 30),
  195. Container(
  196. width: context.width,
  197. height: 1,
  198. color: const Color(0xffD3D8E9),
  199. ),
  200. const SizedBox(height: 30),
  201. AddCommentWidget(sendComment: _cubit.addComment),
  202. if (_cubit.commentList.isEmpty) const SizedBox(height: 30),
  203. const SizedBox(height: 8),
  204. ListView.builder(
  205. shrinkWrap: true,
  206. physics: const NeverScrollableScrollPhysics(),
  207. itemBuilder: (context, index) {
  208. return PostCommentWidget(comment: _cubit.commentList[index]);
  209. },
  210. itemCount: _cubit.commentList.length,
  211. ),
  212. if (_cubit.commentList.isNotEmpty)
  213. Padding(
  214. padding: const EdgeInsets.only(top: 15, bottom: 30),
  215. child: Row(
  216. mainAxisAlignment: MainAxisAlignment.center,
  217. children: [
  218. Text(
  219. Translator.translate('show_all_comments'),
  220. style: const TextStyle(
  221. fontSize: 10,
  222. color: Color(0xff404966),
  223. ),
  224. ),
  225. const SizedBox(width: 4),
  226. SvgPicture.asset(
  227. 'ic_arrow_down'.svgPath,
  228. width: 8,
  229. height: 5,
  230. ),
  231. ],
  232. ),
  233. ),
  234. ],
  235. ),
  236. ),
  237. ],
  238. ),
  239. );
  240. },
  241. ),
  242. ),
  243. );
  244. }
  245. }