status_card_item.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import 'package:cpt_services/components/status_card_item_vm.dart';
  2. import 'package:cpt_services/modules/services/homeService/home_service_page.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:shared/utils/color_utils.dart';
  9. import 'package:shared/utils/ext_dart.dart';
  10. import 'package:shared/utils/log_utils.dart';
  11. import 'package:widgets/ext/ex_widget.dart';
  12. import 'package:widgets/my_button.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import '../constants_services.dart';
  15. class StausCardItem extends HookConsumerWidget {
  16. int serviceId;
  17. int serviceTypeCode;
  18. int serviceStatusCode;
  19. Map<String, dynamic> itemObj;
  20. double? cardHeight ;
  21. final Function(dynamic)? onClickCard;
  22. StausCardItem({
  23. Key? key,
  24. required this.serviceId,
  25. required this.serviceTypeCode,
  26. required this.serviceStatusCode,
  27. required this.itemObj,
  28. this.onClickCard,
  29. cardHeight,
  30. }): super(key: key) {
  31. this.cardHeight = cardHeight ?? 180.0;
  32. }
  33. @override
  34. Widget build(BuildContext context, WidgetRef ref) {
  35. final vm = ref.read(statusCardItemVmProvider.notifier);
  36. final title = itemObj.getValue("title", "House Cleaning Services");
  37. final companyName = itemObj.getValue("company_name", "HONG YE GROUP PTE LTD");
  38. final duration = itemObj.getValue("duration", "Daily cleaning for 2 hours");
  39. final totalPrice = itemObj.getValue("totalPrice", '40');
  40. final visit_time = itemObj.getValue("visit_time", '14 0ct 2024 15:00');
  41. final order_time = itemObj.getValue("order_time", '13 0ct 2024 12:00');
  42. Log.d("serviceStatusCode $serviceStatusCode");
  43. String status_text = servicesConstants.servicesStatus['$serviceStatusCode']['text'];
  44. // final status_text = itemObj.getValue("status_text", "");
  45. List<Map<String, dynamic>>? actionBtnList = servicesConstants.servicesStatusActionBtnList[serviceStatusCode];
  46. // Log.d("actionBtnList $actionBtnList");
  47. useEffect((){
  48. vm.setInitData(context, serviceId, serviceTypeCode, serviceStatusCode);
  49. return () {
  50. };
  51. },[]);
  52. return Container(
  53. width: double.infinity,
  54. height: cardHeight!,
  55. child: Padding(
  56. padding: const EdgeInsets.only(left: 18.0, right: 18.0, top: 22.0, bottom: 22.0),
  57. child: Column(
  58. crossAxisAlignment: CrossAxisAlignment.start,
  59. children: [
  60. Expanded(
  61. child: Column(
  62. crossAxisAlignment: CrossAxisAlignment.start,
  63. children: [
  64. // 标题 和状态
  65. Row(
  66. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  67. children: [
  68. // 标题
  69. Expanded(
  70. child: MyTextView(
  71. title,
  72. fontSize: 16,
  73. maxLines: 1,
  74. isFontMedium: true,
  75. textAlign: TextAlign.left,
  76. ),
  77. ),
  78. // 状态
  79. MyTextView(
  80. status_text,
  81. fontSize: 14,
  82. maxLines: 1,
  83. isFontRegular: true,
  84. textAlign: TextAlign.left,
  85. textColor: context.appColors.textPrimary,
  86. ),
  87. ],
  88. ),
  89. // 公司名称
  90. MyTextView(
  91. companyName,
  92. fontSize: 14,
  93. maxLines: 1,
  94. isFontRegular: true,
  95. textAlign: TextAlign.left,
  96. marginTop: 6,
  97. ),
  98. // 价格
  99. Row(
  100. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  101. children: [
  102. // 公司名称
  103. MyTextView(
  104. duration,
  105. fontSize: 14,
  106. maxLines: 1,
  107. isFontRegular: true,
  108. textAlign: TextAlign.left,
  109. ),
  110. // 公司名称
  111. MyTextView(
  112. '\$$totalPrice',
  113. fontSize: 17,
  114. maxLines: 1,
  115. isFontBold: true,
  116. textAlign: TextAlign.left,
  117. textColor: context.appColors.textPrimary,
  118. ),
  119. ],
  120. ),
  121. SizedBox(height: 7.5,),
  122. // visit time
  123. Row(
  124. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  125. children: [
  126. MyTextView(
  127. 'Visit Time',
  128. fontSize: 14,
  129. maxLines: 1,
  130. isFontRegular: true,
  131. textAlign: TextAlign.left,
  132. ),
  133. MyTextView(
  134. visit_time,
  135. fontSize: 14,
  136. maxLines: 1,
  137. isFontRegular: true,
  138. textAlign: TextAlign.left,
  139. textColor: context.appColors.textBlack,
  140. ),
  141. ],
  142. ),
  143. SizedBox(height: 7.5,),
  144. // order time
  145. Row(
  146. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  147. children: [
  148. MyTextView(
  149. 'Order Time',
  150. fontSize: 14,
  151. maxLines: 1,
  152. isFontRegular: true,
  153. textAlign: TextAlign.left,
  154. ),
  155. MyTextView(
  156. order_time,
  157. fontSize: 14,
  158. maxLines: 1,
  159. isFontRegular: true,
  160. textAlign: TextAlign.left,
  161. textColor: context.appColors.textBlack,
  162. ),
  163. ],
  164. ),
  165. ],
  166. )
  167. ),
  168. // Container(
  169. // margin: EdgeInsets.only(top: 15),
  170. // child: _buildActionSection(context,actionBtnList!, vm, ref),
  171. // ),
  172. ],
  173. ),
  174. ),
  175. );
  176. }
  177. Widget _buildActionSection(BuildContext context,List<Map<String, dynamic>> actionBtnList, StatusCardItemVm vm, WidgetRef ref ) {
  178. return LayoutBuilder(
  179. builder: (BuildContext context, BoxConstraints constraints) {
  180. final maxHeight = constraints.maxHeight;
  181. final minHeight = constraints.minHeight;
  182. final maxWidth = constraints.maxWidth;
  183. // Log.d("---maxHeight-----$maxHeight-- $minHeight $maxWidth--");
  184. return Container(
  185. height: 50,
  186. // color: Colors.red,
  187. width: maxWidth,
  188. child: Row(
  189. mainAxisAlignment: MainAxisAlignment.end,
  190. mainAxisSize: MainAxisSize.max,
  191. children: List.generate(actionBtnList.length, (index){
  192. var item = actionBtnList[index];
  193. // return Expanded(
  194. // child: _buildBtn(context, item),
  195. // );
  196. return _buildBtn(context, item, vm, ref);
  197. })
  198. ),
  199. ).scrollable(
  200. scrollDirection: Axis.horizontal,
  201. physics: BouncingScrollPhysics(),
  202. );
  203. }
  204. );
  205. }
  206. Widget _buildBtn(BuildContext context, Map<String, dynamic> btnItem, StatusCardItemVm vm, WidgetRef ref) {
  207. // final btnCode = btnItem['code'];
  208. return MyButton(
  209. onPressed: (){
  210. vm.handlerClickActionBtn(context, btnItem);
  211. },
  212. text: btnItem['text'],
  213. radius: 10.0,
  214. textColor: context.appColors.textWhite,
  215. backgroundColor: ColorUtils.string2Color(btnItem['btnColor']),
  216. fontSize: 12,
  217. padding: EdgeInsets.symmetric(horizontal: 5),
  218. minWidth: btnItem['btnWidth']?.toDouble(),
  219. minHeight: btnItem['btnHeight']?.toDouble() + 5,
  220. ).marginOnly(left: 5);
  221. }
  222. }