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.

220 lines
9.1 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 Spacer(),
  99. Text(
  100. _cubit.commentList.length.toString(),
  101. style: const TextStyle(
  102. color: Colors.white,
  103. fontSize: 17,
  104. ),
  105. ),
  106. Padding(
  107. padding: const EdgeInsets.all(8),
  108. child: SvgPicture.asset('ic_comment'.svgPath),
  109. ),
  110. const SizedBox(width: 21),
  111. const Text(
  112. '29',
  113. style: TextStyle(
  114. color: Colors.white,
  115. fontSize: 17,
  116. ),
  117. ),
  118. Padding(
  119. padding: const EdgeInsets.all(8),
  120. child: SvgPicture.asset('ic_view'.svgPath),
  121. ),
  122. ],
  123. ),
  124. ),
  125. ),
  126. const Padding(
  127. padding: EdgeInsets.all(8),
  128. child: Align(
  129. alignment: Alignment.bottomCenter,
  130. child: Row(
  131. mainAxisAlignment: MainAxisAlignment.end,
  132. children: [],
  133. ),
  134. ),
  135. ),
  136. ],
  137. ),
  138. ),
  139. Padding(
  140. padding: EdgeInsetsDirectional.only(
  141. start: context.width * 26 / AppConstants.instance.appWidth,
  142. end: context.width * 37 / AppConstants.instance.appWidth,
  143. top: 16,
  144. ),
  145. child: Column(
  146. crossAxisAlignment: CrossAxisAlignment.start,
  147. children: [
  148. Text(
  149. widget.post.name,
  150. style: const TextStyle(
  151. fontWeight: FontWeight.bold,
  152. fontSize: 16,
  153. ),
  154. ),
  155. Text(
  156. Utils.instance.dateToString(widget.post.date),
  157. style: const TextStyle(fontSize: 11),
  158. ),
  159. HTMLViewer(
  160. htmlContent: widget.post.description,
  161. fontSizeFactor: 1,
  162. ),
  163. const SizedBox(height: 30),
  164. Container(
  165. width: context.width,
  166. height: 1,
  167. color: const Color(0xffD3D8E9),
  168. ),
  169. const SizedBox(height: 30),
  170. AddCommentWidget(sendComment: _cubit.addComment),
  171. if (_cubit.commentList.isEmpty) const SizedBox(height: 30),
  172. const SizedBox(height: 8),
  173. ListView.builder(
  174. shrinkWrap: true,
  175. physics: const NeverScrollableScrollPhysics(),
  176. itemBuilder: (context, index) {
  177. return PostCommentWidget(comment: _cubit.commentList[index]);
  178. },
  179. itemCount: _cubit.commentList.length,
  180. ),
  181. if (_cubit.commentList.isNotEmpty)
  182. Padding(
  183. padding: const EdgeInsets.only(top: 15, bottom: 30),
  184. child: Row(
  185. mainAxisAlignment: MainAxisAlignment.center,
  186. children: [
  187. Text(
  188. Translator.translate('show_all_comments'),
  189. style: const TextStyle(
  190. fontSize: 10,
  191. color: Color(0xff404966),
  192. ),
  193. ),
  194. const SizedBox(width: 4),
  195. SvgPicture.asset(
  196. 'ic_arrow_down'.svgPath,
  197. width: 8,
  198. height: 5,
  199. ),
  200. ],
  201. ),
  202. ),
  203. ],
  204. ),
  205. ),
  206. ],
  207. ),
  208. );
  209. },
  210. ),
  211. ),
  212. );
  213. }
  214. }