service_card_item.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
  17. // 'title': 'Electronic keyboard',
  18. // 'price': '\$66',
  19. // 'isCollection': true,
  20. // 'collection_num': '12',
  21. // 'publisher': 'William Jefferson',
  22. // 'publish_time': 'June 17,2016 at 7:23 p.m.',
  23. // 'publisher_avator': Assets.communityCamera,'
  24. class HomeServiceCard extends StatelessWidget {
  25. Map<String, dynamic>? serviceType = servicesConstants.servicesType['houseCleaning'];
  26. Map<String, dynamic> itemObj;
  27. double? cardHeight;
  28. final Function()? onTap;
  29. final Function(dynamic)? onClickColleciotn;
  30. HomeServiceCard({
  31. Key? key,
  32. this.serviceType,
  33. required this.itemObj,
  34. this.onTap,
  35. this.onClickColleciotn,
  36. double? cardHeight,
  37. }) : super(key: key) {
  38. this.cardHeight ??= 214;
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. List? card_resources = itemObj.getValue<List>("resources", [])?? [];
  43. String card_img = card_resources.length>0? card_resources[0]:"";
  44. String card_title = itemObj.getValue("title", "");
  45. int card_price = itemObj.getValue("price", "");
  46. String card_created_at = itemObj.getValue("created_at", "");
  47. Map<String, dynamic>? card_account = itemObj.getValue<Map<String,dynamic>>("account", null);
  48. String card_avatar = card_account?['avatar']?? "";
  49. String card_publish_name = card_account?['name']?? "";
  50. bool card_liked = itemObj.getValue("liked", false);
  51. int card_likes_count = itemObj.getValue("likes_count", 0);
  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: 166.5,
  65. height: 102.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, bottom: 10),
  76. child: Row(
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. children: [
  79. Expanded(
  80. child: MyTextView(
  81. card_title,
  82. maxLines: 1,
  83. isTextEllipsis: true,
  84. textAlign: TextAlign.left,
  85. textColor: context.appColors.textBlack,
  86. fontSize: 16,
  87. isFontRegular: true,
  88. ),
  89. ),
  90. ],
  91. ),
  92. ),
  93. // 价格 及 收藏
  94. Padding(
  95. padding: const EdgeInsets.only(left: 10, right: 10,top: 0, bottom: 0),
  96. child: Row(
  97. mainAxisAlignment: MainAxisAlignment.spaceAround,
  98. crossAxisAlignment: CrossAxisAlignment.center,
  99. children: [
  100. Expanded(
  101. child: MyTextView(
  102. '$card_price',
  103. maxLines: 1,
  104. isTextEllipsis: true,
  105. textAlign: TextAlign.start,
  106. textColor: ColorUtils.string2Color('#4161D0'),
  107. fontSize: 18,
  108. isFontMedium: true,
  109. ),
  110. ),
  111. // 动态的 收藏数
  112. CollectionWidget(
  113. collectionNum: card_likes_count,
  114. isCollection: card_liked,
  115. onClickColleciotn: onClickColleciotn,
  116. ),
  117. ],
  118. ),
  119. ),
  120. // 发布人信息
  121. Expanded(
  122. child: Padding(
  123. padding: EdgeInsets.only(left: 10, right: 10, bottom: 17.5),
  124. child: Row(
  125. mainAxisAlignment: MainAxisAlignment.spaceAround,
  126. crossAxisAlignment: CrossAxisAlignment.center,
  127. children: [
  128. Expanded(
  129. child: Column(
  130. mainAxisAlignment: MainAxisAlignment.center,
  131. crossAxisAlignment: CrossAxisAlignment.start,
  132. mainAxisSize: MainAxisSize.max,
  133. children: [
  134. MyTextView(
  135. card_publish_name,
  136. maxLines: 1,
  137. isTextEllipsis: true,
  138. textAlign: TextAlign.start,
  139. marginLeft: 13,
  140. fontSize: 12,
  141. textColor: ColorUtils.string2Color('#2956B7'),
  142. isFontRegular: true,
  143. ),
  144. MyTextView(
  145. card_created_at,
  146. maxLines: 1,
  147. isTextEllipsis: true,
  148. textAlign: TextAlign.start,
  149. marginLeft: 13,
  150. marginTop: 5,
  151. fontSize: 10,
  152. textColor: context.appColors.textBlack,
  153. isFontRegular: true,
  154. ),
  155. ]
  156. )
  157. ),
  158. ]
  159. )
  160. ),
  161. )
  162. ],
  163. );
  164. }
  165. }
  166. class CollectionWidget extends HookConsumerWidget {
  167. int collectionNum = 0;
  168. bool isCollection = false;
  169. final Function(dynamic)? onClickColleciotn;
  170. CollectionWidget({
  171. Key? key,
  172. required this.collectionNum,
  173. required this.isCollection,
  174. this.onClickColleciotn,
  175. }) : super(key: key);
  176. @override
  177. Widget build(BuildContext context, WidgetRef ref) {
  178. final collectionNumState = useState(collectionNum);
  179. final isCollectionState = useState(isCollection);
  180. return Container(
  181. width: 60,
  182. height: 30,
  183. alignment: Alignment.center,
  184. // decoration: BoxDecoration(
  185. // color: ColorUtils.string2Color('#E5E5E5'),
  186. // borderRadius: BorderRadius.circular(15),
  187. // ),
  188. child: Row(
  189. mainAxisAlignment: MainAxisAlignment.center,
  190. children: [
  191. MyTextView(
  192. '${collectionNumState.value}',
  193. textColor: context.appColors.textBlack,
  194. fontSize: 14,
  195. isFontRegular: true,
  196. marginRight: 7,
  197. ),
  198. MyLoadImage(
  199. isCollectionState.value? Assets.communityLikeActive: Assets.communityLike,
  200. width: 14.1,
  201. height: 14,
  202. )
  203. ]
  204. // 点击 收餐/取消收藏
  205. ).onTap(() async{
  206. // Log.d("点击了收藏按钮 ${isCollectionState.value}");
  207. // ToastEngine.show("点击了收藏按钮 ${isCollectionState.value}");
  208. final result = await onClickColleciotn?.call(isCollectionState.value);
  209. if(result !=null && result){
  210. isCollectionState.value = !isCollectionState.value;
  211. collectionNumState.value = (collectionNumState.value + (isCollectionState.value? 1: -1))<0? 0: (collectionNumState.value + (isCollectionState.value? 1: -1));
  212. if(isCollectionState.value){
  213. // ToastEngine.show("Collect Success");
  214. }else {
  215. // ToastEngine.show("Cancel Collect Success");
  216. }
  217. }
  218. })
  219. );
  220. }
  221. }