garage_card.dart 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
  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. class GarageCard extends StatelessWidget {
  24. Map<String, dynamic> itemObj;
  25. double? cardHeight;
  26. final Function()? onTap;
  27. final Function(dynamic)? onClickColleciotn;
  28. GarageCard({
  29. Key? key,
  30. required this.itemObj,
  31. this.onTap,
  32. this.onClickColleciotn,
  33. double? cardHeight,
  34. }) : super(key: key) {
  35. this.cardHeight ??= 214;
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Container(
  40. // height: cardHeight,
  41. child: Expanded(
  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. itemObj['goods_img'],
  54. width: 166.5,
  55. height: 102.5,
  56. isCircle: false,
  57. fit: BoxFit.cover,
  58. ).onTap(() {
  59. // 点击头像
  60. // onTap?.call();
  61. }),
  62. ),
  63. ),
  64. ],
  65. ),
  66. // 标题
  67. Padding(
  68. padding: const EdgeInsets.only(left: 10, right: 10, top: 12, bottom: 12),
  69. child: Row(
  70. mainAxisAlignment: MainAxisAlignment.center,
  71. children: [
  72. Expanded(
  73. child: MyTextView(
  74. itemObj['title'],
  75. maxLines: 1,
  76. isTextEllipsis: true,
  77. textAlign: TextAlign.left,
  78. textColor: context.appColors.textBlack,
  79. fontSize: 16,
  80. isFontRegular: true,
  81. ),
  82. ),
  83. ],
  84. ),
  85. ),
  86. // 价格 及 收藏
  87. Padding(
  88. padding: const EdgeInsets.only(left: 10, right: 10,top: 10, bottom: 10),
  89. child: Row(
  90. mainAxisAlignment: MainAxisAlignment.spaceAround,
  91. crossAxisAlignment: CrossAxisAlignment.center,
  92. children: [
  93. Expanded(
  94. child: MyTextView(
  95. itemObj['price'],
  96. maxLines: 1,
  97. isTextEllipsis: true,
  98. textAlign: TextAlign.start,
  99. textColor: ColorUtils.string2Color('#4161D0'),
  100. fontSize: 18,
  101. isFontMedium: true,
  102. ),
  103. ),
  104. // 动态的 收藏数
  105. CollectionWidget(
  106. collectionNum: itemObj['collection_num'],
  107. isCollection: itemObj['isCollection'],
  108. onClickColleciotn: onClickColleciotn,
  109. ),
  110. ],
  111. ),
  112. ),
  113. // 发布人信息
  114. Expanded(
  115. child: Padding(
  116. padding: const EdgeInsets.only(left: 10, right: 10),
  117. child: Row(
  118. mainAxisAlignment: MainAxisAlignment.spaceAround,
  119. crossAxisAlignment: CrossAxisAlignment.center,
  120. children: [
  121. MyLoadImage(
  122. itemObj['publisher_avator'],
  123. width: 30,
  124. height: 30,
  125. isCircle: true,
  126. ),
  127. Expanded(
  128. child: Column(
  129. mainAxisAlignment: MainAxisAlignment.center,
  130. crossAxisAlignment: CrossAxisAlignment.start,
  131. mainAxisSize: MainAxisSize.max,
  132. children: [
  133. MyTextView(
  134. itemObj['publisher'],
  135. maxLines: 1,
  136. isTextEllipsis: true,
  137. textAlign: TextAlign.start,
  138. marginLeft: 13,
  139. fontSize: 12,
  140. textColor: ColorUtils.string2Color('#2956B7'),
  141. isFontRegular: true,
  142. ),
  143. MyTextView(
  144. itemObj['publish_time'],
  145. maxLines: 1,
  146. isTextEllipsis: true,
  147. textAlign: TextAlign.start,
  148. marginLeft: 13,
  149. marginTop: 5,
  150. fontSize: 10,
  151. textColor: context.appColors.textBlack,
  152. isFontRegular: true,
  153. ),
  154. ]
  155. )
  156. ),
  157. ]
  158. )
  159. ),
  160. )
  161. ],
  162. ),
  163. ),
  164. );
  165. }
  166. }
  167. class CollectionWidget extends HookConsumerWidget {
  168. int collectionNum = 0;
  169. bool isCollection = false;
  170. final Function(dynamic)? onClickColleciotn;
  171. CollectionWidget({
  172. Key? key,
  173. required this.collectionNum,
  174. required this.isCollection,
  175. this.onClickColleciotn,
  176. }) : super(key: key);
  177. @override
  178. Widget build(BuildContext context, WidgetRef ref) {
  179. final collectionNumState = useState(collectionNum);
  180. final isCollectionState = useState(isCollection);
  181. return Container(
  182. width: 60,
  183. height: 30,
  184. alignment: Alignment.center,
  185. // decoration: BoxDecoration(
  186. // color: ColorUtils.string2Color('#E5E5E5'),
  187. // borderRadius: BorderRadius.circular(15),
  188. // ),
  189. child: Row(
  190. mainAxisAlignment: MainAxisAlignment.center,
  191. children: [
  192. MyTextView(
  193. '${collectionNumState.value}',
  194. textColor: ColorUtils.string2Color('#000000'),
  195. fontSize: 14,
  196. isFontRegular: true,
  197. marginRight: 7,
  198. ),
  199. MyLoadImage(
  200. isCollectionState.value? Assets.communityLikeActive: Assets.communityLike,
  201. width: 15,
  202. height: 14,
  203. )
  204. ]
  205. // 点击 收餐/取消收藏
  206. ).onTap((){
  207. // Log.d("点击了收藏按钮 ${isCollectionState.value}");
  208. // ToastEngine.show("点击了收藏按钮 ${isCollectionState.value}");
  209. bool result = onClickColleciotn?.call(isCollectionState.value);
  210. if(result){
  211. isCollectionState.value = !isCollectionState.value;
  212. if(isCollectionState.value){
  213. ToastEngine.show("Collect Success");
  214. }else {
  215. ToastEngine.show("Cancel Collect Success");
  216. }
  217. }
  218. })
  219. );
  220. }
  221. }