service_card_item.dart 8.4 KB

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