service_card_item.dart 7.6 KB

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