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.

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