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.

235 lines
7.2KB

  1. import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
  2. import 'package:farm_tpf/presentation/custom_widgets/button/second_button.dart';
  3. import 'package:farm_tpf/presentation/screens/codes/cubit/detail_stamp_cubit.dart';
  4. import 'package:farm_tpf/presentation/screens/codes/models/stamp_timeline.dart';
  5. import 'package:farm_tpf/presentation/screens/codes/update_activity_page.dart';
  6. import 'package:farm_tpf/presentation/screens/codes/widgets/item_code_timeline.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_bloc/flutter_bloc.dart';
  9. import 'package:get/get.dart';
  10. import 'package:farm_tpf/utils/formatter.dart';
  11. import '../../../themes/styles_text.dart';
  12. import '../../custom_widgets/loading_list_page.dart';
  13. class CodeDetailPage extends StatefulWidget {
  14. final int stampId;
  15. final String stampCode;
  16. const CodeDetailPage({
  17. super.key,
  18. required this.stampId,
  19. required this.stampCode,
  20. });
  21. @override
  22. State<CodeDetailPage> createState() => _CodeDetailPageState();
  23. }
  24. class _CodeDetailPageState extends State<CodeDetailPage> {
  25. var bloc = DetailStampCubit();
  26. @override
  27. void initState() {
  28. super.initState();
  29. bloc.preparedData(widget.stampId);
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. return Scaffold(
  34. appBar: AppBarWidget(
  35. action: IconButton(
  36. onPressed: () {
  37. // Get.to(
  38. // () => UpdateActivityPage(
  39. // stampCode: widget.stampCode,
  40. // ),
  41. // );
  42. },
  43. icon: Icon(
  44. Icons.edit,
  45. color: Colors.blue,
  46. ),
  47. ),
  48. ),
  49. body: Padding(
  50. padding: const EdgeInsets.all(8.0),
  51. child: Column(
  52. children: [
  53. Expanded(
  54. child: BlocBuilder<DetailStampCubit, DetailStampState>(
  55. bloc: bloc,
  56. builder: (context, state) {
  57. if (state is DetailStampLoading) {
  58. return Center(
  59. child: LoadingListPage(),
  60. );
  61. } else if (state is DetailStampFailure) {
  62. return Center(child: Text(state.errorMessage));
  63. } else if (state is DetailStampSuccessful) {
  64. var stamp = state.stamp;
  65. return SingleChildScrollView(
  66. child: Column(
  67. children: [
  68. _itemCodeDetail(
  69. title: 'Tên sản phẩm',
  70. detail: 'Cà rốt',
  71. titleStyle: StylesText.body4,
  72. detailStyle: StylesText.body4.copyWith(
  73. color: Colors.blue,
  74. ),
  75. ),
  76. _itemCodeDetail(title: 'Mô tả', detail: stamp.description ?? ''),
  77. _itemCodeDetail(title: 'Số lượng tem', detail: stamp.quantity?.formatNumtoStringDecimal().toString() ?? ''),
  78. _itemCodeDetail(title: 'Trạng thái', detail: stamp.status ?? ''),
  79. _itemCodeDetail(title: 'Hạn sử dụng', detail: stamp.expiredDate?.format_DDMMYY().toString() ?? ''),
  80. _itemCodeDetail(title: 'Mẫu tem', detail: stamp.stampType?.exampleStampName ?? ''),
  81. const SizedBox(
  82. height: 8,
  83. ),
  84. Text(
  85. 'Timeline hoạt động',
  86. style: StylesText.body1,
  87. ),
  88. const SizedBox(
  89. height: 8,
  90. ),
  91. _timelineWidget(state.timeline),
  92. ],
  93. ),
  94. );
  95. }
  96. return const SizedBox.shrink();
  97. },
  98. )),
  99. const SizedBox(
  100. height: 8,
  101. ),
  102. _actionButtonWidget(),
  103. ],
  104. ),
  105. ),
  106. );
  107. }
  108. Widget _timelineWidget(StampTimeline timeline) {
  109. if ((timeline.content?.length ?? 0) == 0) return const SizedBox.shrink();
  110. return ListView.builder(
  111. itemBuilder: (context, index) {
  112. return ItemCodeTimeline(
  113. item: timeline.content![index],
  114. onPressed: () {},
  115. );
  116. },
  117. itemCount: timeline.content?.length ?? 0,
  118. physics: NeverScrollableScrollPhysics(),
  119. shrinkWrap: true,
  120. );
  121. }
  122. Widget _actionButtonWidget() {
  123. return Wrap(
  124. spacing: 8,
  125. children: [
  126. Row(
  127. children: [
  128. Expanded(
  129. child: SecondButton(
  130. onPressed: () {
  131. bloc.updateStampStatus(
  132. stampId: widget.stampId,
  133. status: 'ACTIVE',
  134. );
  135. },
  136. title: 'Kích hoạt toàn bộ',
  137. borderColor: Colors.blue,
  138. textColor: Colors.blue,
  139. width: double.infinity,
  140. height: 40,
  141. ),
  142. ),
  143. Expanded(
  144. child: SecondButton(
  145. onPressed: () {
  146. bloc.updateStampStatus(
  147. stampId: widget.stampId,
  148. status: 'CANCELED',
  149. );
  150. },
  151. title: 'Huỷ toàn bộ',
  152. borderColor: Colors.red,
  153. textColor: Colors.white,
  154. color: Colors.red,
  155. width: double.infinity,
  156. height: 40,
  157. ),
  158. ),
  159. ],
  160. ),
  161. const SizedBox(
  162. height: 8,
  163. ),
  164. Row(
  165. children: [
  166. Expanded(
  167. child: SecondButton(
  168. onPressed: () {
  169. Get.to(
  170. () => UpdateActivityPage(
  171. stampCode: widget.stampCode,
  172. ),
  173. )?.then((value) {
  174. if (value != null) {
  175. bloc.preparedData(widget.stampId);
  176. }
  177. });
  178. },
  179. title: 'Cập nhật hoạt động',
  180. borderColor: Colors.green,
  181. textColor: Colors.green,
  182. width: double.infinity,
  183. height: 40,
  184. ),
  185. ),
  186. Expanded(
  187. child: SecondButton(
  188. onPressed: () {},
  189. title: 'In / Xuất file',
  190. borderColor: Colors.cyan,
  191. textColor: Colors.white,
  192. color: Colors.cyan,
  193. width: double.infinity,
  194. height: 40,
  195. ),
  196. ),
  197. ],
  198. ),
  199. ],
  200. );
  201. }
  202. Widget _itemCodeDetail({
  203. required String title,
  204. required String detail,
  205. TextStyle? titleStyle,
  206. TextStyle? detailStyle,
  207. }) {
  208. return Padding(
  209. padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
  210. child: Row(
  211. children: [
  212. Expanded(
  213. child: Text(
  214. title,
  215. style: titleStyle ?? StylesText.body6,
  216. ),
  217. ),
  218. Text(
  219. detail,
  220. style: detailStyle ?? StylesText.body6,
  221. )
  222. ],
  223. ),
  224. );
  225. }
  226. }