service_card_item.dart 7.8 KB

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