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.

231 lines
9.5 KiB

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