garage_card.dart 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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/log_utils.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. import '../modules/garage/for_sale/for_sale_vm.dart';
  14. // 'id':1,
  15. // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
  16. // 'title': 'Electronic keyboard',
  17. // 'price': '\$66',
  18. // 'isCollection': true,
  19. // 'collection_num': '12',
  20. // 'publisher': 'William Jefferson',
  21. // 'publish_time': 'June 17,2016 at 7:23 p.m.',
  22. // 'publisher_avator': Assets.communityCamera,'
  23. // 定义一个 使用场景的 枚举
  24. enum GarageCardUseType {
  25. // 默认
  26. forSale,
  27. forRent,
  28. myPostsForSale,
  29. myPostsForRent,
  30. }
  31. class GarageCard extends StatelessWidget {
  32. GarageCardUseType? useType;
  33. Map<String, dynamic> itemObj;
  34. double? cardHeight;
  35. final Function()? onTap;
  36. final Function(dynamic)? onClickColleciotn;
  37. GarageCard({
  38. Key? key,
  39. this.useType = GarageCardUseType.forSale,
  40. required this.itemObj,
  41. this.onTap,
  42. this.onClickColleciotn,
  43. double? cardHeight,
  44. }) : super(key: key) {
  45. this.cardHeight ??= 214;
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return Column(
  50. children: [
  51. // 图片
  52. Row(
  53. mainAxisAlignment: MainAxisAlignment.center,
  54. crossAxisAlignment: CrossAxisAlignment.center,
  55. children: [
  56. Expanded(
  57. child: ClipRRect(
  58. borderRadius: const BorderRadius.only(topLeft: Radius.circular(8), topRight: Radius.circular(8),),
  59. child: MyLoadImage(
  60. itemObj['goods_img'],
  61. width: 166.5,
  62. height: 102.5,
  63. isCircle: false,
  64. fit: BoxFit.cover,
  65. ).onTap(() {
  66. // 点击头像
  67. // onTap?.call();
  68. }),
  69. ),
  70. ),
  71. ],
  72. ),
  73. // 标题
  74. Padding(
  75. padding: const EdgeInsets.only(left: 10, right: 10, top: 12, bottom: 12),
  76. child: Row(
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. children: [
  79. Expanded(
  80. child: MyTextView(
  81. itemObj['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: 10, bottom: 10),
  96. child: Row(
  97. mainAxisAlignment: MainAxisAlignment.spaceAround,
  98. crossAxisAlignment: CrossAxisAlignment.center,
  99. children: [
  100. Expanded(
  101. child: MyTextView(
  102. itemObj['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: itemObj['collection_num'],
  114. isCollection: itemObj['isCollection'],
  115. onClickColleciotn: onClickColleciotn,
  116. ),
  117. ],
  118. ),
  119. ),
  120. // 发布人信息
  121. Expanded(
  122. child: Padding(
  123. padding: EdgeInsets.only(left: (useType == GarageCardUseType.forSale || useType == GarageCardUseType.forRent)?10:0, right: 10),
  124. child: Row(
  125. mainAxisAlignment: MainAxisAlignment.spaceAround,
  126. crossAxisAlignment: CrossAxisAlignment.center,
  127. children: [
  128. if (useType == GarageCardUseType.forSale || useType == GarageCardUseType.forRent)
  129. MyLoadImage(
  130. itemObj['publisher_avator'],
  131. width: 30,
  132. height: 30,
  133. isCircle: true,
  134. )
  135. else
  136. const SizedBox.shrink(),
  137. Expanded(
  138. child: Column(
  139. mainAxisAlignment: MainAxisAlignment.center,
  140. crossAxisAlignment: CrossAxisAlignment.start,
  141. mainAxisSize: MainAxisSize.max,
  142. children: [
  143. if (useType == GarageCardUseType.forSale || useType == GarageCardUseType.forRent)
  144. MyTextView(
  145. itemObj['publisher'],
  146. maxLines: 1,
  147. isTextEllipsis: true,
  148. textAlign: TextAlign.start,
  149. marginLeft: 13,
  150. fontSize: 12,
  151. textColor: ColorUtils.string2Color('#2956B7'),
  152. isFontRegular: true,
  153. )
  154. else
  155. const SizedBox.shrink(),
  156. MyTextView(
  157. itemObj['publish_time'],
  158. maxLines: 1,
  159. isTextEllipsis: true,
  160. textAlign: TextAlign.start,
  161. marginLeft: 13,
  162. marginTop: 5,
  163. fontSize: 10,
  164. textColor: context.appColors.textBlack,
  165. isFontRegular: true,
  166. ),
  167. ]
  168. )
  169. ),
  170. ]
  171. )
  172. ),
  173. )
  174. ],
  175. );
  176. }
  177. }
  178. class CollectionWidget extends HookConsumerWidget {
  179. int collectionNum = 0;
  180. bool isCollection = false;
  181. final Function(dynamic)? onClickColleciotn;
  182. CollectionWidget({
  183. Key? key,
  184. required this.collectionNum,
  185. required this.isCollection,
  186. this.onClickColleciotn,
  187. }) : super(key: key);
  188. @override
  189. Widget build(BuildContext context, WidgetRef ref) {
  190. final collectionNumState = useState(collectionNum);
  191. final isCollectionState = useState(isCollection);
  192. return Container(
  193. width: 60,
  194. height: 30,
  195. alignment: Alignment.center,
  196. // decoration: BoxDecoration(
  197. // color: ColorUtils.string2Color('#E5E5E5'),
  198. // borderRadius: BorderRadius.circular(15),
  199. // ),
  200. child: Row(
  201. mainAxisAlignment: MainAxisAlignment.center,
  202. children: [
  203. MyTextView(
  204. '${collectionNumState.value}',
  205. textColor: context.appColors.textBlack,
  206. fontSize: 14,
  207. isFontRegular: true,
  208. marginRight: 7,
  209. ),
  210. MyLoadImage(
  211. isCollectionState.value? Assets.communityLikeActive: Assets.communityLike,
  212. width: 15,
  213. height: 14,
  214. )
  215. ]
  216. // 点击 收餐/取消收藏
  217. ).onTap((){
  218. // Log.d("点击了收藏按钮 ${isCollectionState.value}");
  219. // ToastEngine.show("点击了收藏按钮 ${isCollectionState.value}");
  220. bool result = onClickColleciotn?.call(isCollectionState.value);
  221. if(result){
  222. isCollectionState.value = !isCollectionState.value;
  223. if(isCollectionState.value){
  224. ToastEngine.show("Collect Success");
  225. }else {
  226. ToastEngine.show("Cancel Collect Success");
  227. }
  228. }
  229. })
  230. );
  231. }
  232. }