service_card_item.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/widgets.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:plugin_platform/engine/toast/toast_engine.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_load_image.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import '../../../constants_services.dart';
  15. // 'id':1,
  16. // 'service_type': 0, // 0 房屋保洁 1 空调保洁 2 维修
  17. // 'cover_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
  18. // 'resources': ['https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500'],
  19. // 'title': 'House Cleaning Services',
  20. // 'price': 66,
  21. // 'unit': '/hr',
  22. // 'liked': true,
  23. // 'likes_count': 1212,
  24. // 'company_name': 'HONG YE GROUP PTE LTD',
  25. class HomeServiceCard extends StatelessWidget {
  26. Map<String, dynamic>? serviceType = servicesConstants.servicesType['houseCleaning'];
  27. Map<String, dynamic> itemObj;
  28. double? cardHeight;
  29. final Function()? onTap;
  30. final Function(dynamic)? onClickColleciotn;
  31. HomeServiceCard({
  32. Key? key,
  33. this.serviceType,
  34. required this.itemObj,
  35. this.onTap,
  36. this.onClickColleciotn,
  37. double? cardHeight,
  38. }) : super(key: key) {
  39. this.cardHeight ??= 170;
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. List? card_resources = itemObj.getValue<List>("resources", [])?? [];
  44. String card_img = card_resources.length>0? card_resources[0]:"";
  45. String card_title = itemObj.getValue("title", "");
  46. final unit = itemObj.getValue("unit", "");
  47. int card_price = itemObj.getValue("price", "");
  48. String card_created_at = itemObj.getValue("created_at", "");
  49. bool card_liked = itemObj.getValue("liked", false);
  50. int card_likes_count = itemObj.getValue("likes_count", 0);
  51. final company_name = itemObj.getValue("company_name", "");
  52. return Column(
  53. children: [
  54. // 图片
  55. Row(
  56. mainAxisAlignment: MainAxisAlignment.center,
  57. crossAxisAlignment: CrossAxisAlignment.center,
  58. children: [
  59. Expanded(
  60. child: ClipRRect(
  61. borderRadius: const BorderRadius.only(topLeft: Radius.circular(8), topRight: Radius.circular(8),),
  62. child: MyLoadImage(
  63. card_img,
  64. width: 172.5,
  65. height: 80.5.ap,
  66. isCircle: false,
  67. fit: BoxFit.cover,
  68. ),
  69. ),
  70. ),
  71. ],
  72. ),
  73. // 标题
  74. Padding(
  75. padding: const EdgeInsets.only(left: 10, right: 10, top: 10,),
  76. child: Row(
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. children: [
  79. Expanded(
  80. child: SizedBox(
  81. height: 30.ap,
  82. child: MyTextView(
  83. card_title,
  84. maxLines: 2,
  85. isTextEllipsis: true,
  86. textAlign: TextAlign.left,
  87. textColor: context.appColors.textBlack,
  88. fontSize: 15,
  89. isFontRegular: true,
  90. ),
  91. ),
  92. ),
  93. ],
  94. ),
  95. ),
  96. // 价格 及 收藏
  97. Padding(
  98. padding: const EdgeInsets.only(left: 10, right: 10,top: 0, bottom: 0),
  99. child: Row(
  100. mainAxisAlignment: MainAxisAlignment.spaceAround,
  101. crossAxisAlignment: CrossAxisAlignment.center,
  102. children: [
  103. Expanded(
  104. child: Row(
  105. mainAxisAlignment: MainAxisAlignment.start,
  106. crossAxisAlignment: CrossAxisAlignment.center,
  107. children: [
  108. MyTextView(
  109. 'from',
  110. maxLines: 1,
  111. isTextEllipsis: true,
  112. textAlign: TextAlign.start,
  113. textColor: ColorUtils.string2Color('#666666'),
  114. fontSize: 11,
  115. isFontMedium: true,
  116. ),
  117. MyTextView(
  118. '\$$card_price',
  119. maxLines: 1,
  120. isTextEllipsis: true,
  121. textAlign: TextAlign.start,
  122. textColor: ColorUtils.string2Color('#4161D0'),
  123. fontSize: 15,
  124. isFontMedium: true,
  125. marginLeft: 2,
  126. ),
  127. MyTextView(
  128. '$unit',
  129. maxLines: 1,
  130. isTextEllipsis: true,
  131. textAlign: TextAlign.start,
  132. textColor: ColorUtils.string2Color('#666666'),
  133. fontSize: 11,
  134. isFontMedium: true,
  135. ),
  136. ],
  137. ),
  138. ),
  139. // 动态的 收藏数
  140. CollectionWidget(
  141. collectionNum: card_likes_count,
  142. isCollection: card_liked,
  143. onClickColleciotn: onClickColleciotn,
  144. ),
  145. ],
  146. ),
  147. ),
  148. // 公司名称
  149. Expanded(
  150. child: Padding(
  151. padding: const EdgeInsets.only(bottom: 5),
  152. child: MyTextView(
  153. company_name,
  154. maxLines: 1,
  155. isTextEllipsis: true,
  156. textAlign: TextAlign.start,
  157. marginLeft: 13,
  158. fontSize: 11,
  159. textColor: ColorUtils.string2Color('#666666'),
  160. alignment: Alignment.centerLeft,
  161. isFontRegular: true,
  162. ),
  163. ),
  164. )
  165. ],
  166. );
  167. }
  168. }
  169. class CollectionWidget extends HookConsumerWidget {
  170. int collectionNum = 0;
  171. bool isCollection = false;
  172. final Function(dynamic)? onClickColleciotn;
  173. CollectionWidget({
  174. Key? key,
  175. required this.collectionNum,
  176. required this.isCollection,
  177. this.onClickColleciotn,
  178. }) : super(key: key);
  179. @override
  180. Widget build(BuildContext context, WidgetRef ref) {
  181. final collectionNumState = useState(collectionNum);
  182. final isCollectionState = useState(isCollection);
  183. return Container(
  184. width: 60,
  185. height: 30,
  186. alignment: Alignment.center,
  187. // decoration: BoxDecoration(
  188. // color: ColorUtils.string2Color('#E5E5E5'),
  189. // borderRadius: BorderRadius.circular(15),
  190. // ),
  191. child: Row(
  192. mainAxisAlignment: MainAxisAlignment.center,
  193. children: [
  194. MyTextView(
  195. '${collectionNumState.value}',
  196. textColor: context.appColors.textBlack,
  197. fontSize: 14,
  198. isFontRegular: true,
  199. marginRight: 7,
  200. ),
  201. MyLoadImage(
  202. isCollectionState.value? Assets.communityLikeActive: Assets.communityLike,
  203. width: 14.1,
  204. height: 14,
  205. )
  206. ]
  207. // 点击 收餐/取消收藏
  208. ).onTap(() async{
  209. // Log.d("点击了收藏按钮 ${isCollectionState.value}");
  210. // ToastEngine.show("点击了收藏按钮 ${isCollectionState.value}");
  211. final result = await onClickColleciotn?.call(isCollectionState.value);
  212. if(result !=null && result){
  213. isCollectionState.value = !isCollectionState.value;
  214. collectionNumState.value = (collectionNumState.value + (isCollectionState.value? 1: -1))<0? 0: (collectionNumState.value + (isCollectionState.value? 1: -1));
  215. if(isCollectionState.value){
  216. // ToastEngine.show("Collect Success");
  217. }else {
  218. // ToastEngine.show("Cancel Collect Success");
  219. }
  220. }
  221. })
  222. );
  223. }
  224. }