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.

225 lines
7.1KB

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