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.

230 lines
9.6 KiB

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