garage_card.dart 7.4 KB

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