garage_card_header.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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:shared/utils/color_utils.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:widgets/ext/ex_widget.dart';
  10. import 'package:widgets/my_load_image.dart';
  11. import 'package:widgets/my_text_view.dart';
  12. import '../modules/garage/for_sale/for_sale_vm.dart';
  13. // 'id':1,
  14. // 'goods_img': 'https://img.alicdn.com/tfs/TB1h.o9O4MPMeJjy1XaXXcSsFXa-640-360.jpg',
  15. // 'title': 'Electronic keyboard',
  16. // 'price': '\$66',
  17. // 'isCollection': true,
  18. // 'collection_num': '12',
  19. // 'publisher': 'William Jefferson',
  20. // 'publish_time': 'June 17,2016 at 7:23 p.m.',
  21. // 'publisher_avator': Assets.communityCamera,'
  22. class GarageCardHeader extends StatelessWidget {
  23. Map<String, dynamic> itemObj;
  24. final Function()? onTap;
  25. GarageCardHeader({
  26. Key? key,
  27. required this.itemObj,
  28. this.onTap,
  29. }) : super(key: key);
  30. @override
  31. Widget build(BuildContext context) {
  32. return Column(
  33. children: [
  34. Row(
  35. mainAxisAlignment: MainAxisAlignment.center,
  36. crossAxisAlignment: CrossAxisAlignment.center,
  37. children: [
  38. Expanded(
  39. child: MyLoadImage(
  40. itemObj['goods_img'],
  41. width: 166.5,
  42. height: 102.5,
  43. isCircle: false,
  44. fit: BoxFit.cover,
  45. ).onTap(() {
  46. // 点击头像
  47. // onTap?.call();
  48. }),
  49. ),
  50. ],
  51. ),
  52. Row(
  53. mainAxisAlignment: MainAxisAlignment.center,
  54. children: [
  55. Expanded(
  56. child: MyTextView(
  57. itemObj['title'],
  58. maxLines: 1,
  59. isTextEllipsis: true,
  60. textAlign: TextAlign.center,
  61. textColor: context.appColors.textBlack,
  62. fontSize: 16,
  63. isFontRegular: true,
  64. marginLeft: 12,
  65. marginRight: 12,
  66. ),
  67. ),
  68. ],
  69. ),
  70. Row(
  71. mainAxisAlignment: MainAxisAlignment.spaceAround,
  72. crossAxisAlignment: CrossAxisAlignment.center,
  73. children: [
  74. Expanded(
  75. child: MyTextView(
  76. itemObj['price'],
  77. maxLines: 1,
  78. isTextEllipsis: true,
  79. textAlign: TextAlign.start,
  80. textColor: ColorUtils.string2Color('#4161D0'),
  81. fontSize: 18,
  82. isFontMedium: true,
  83. ),
  84. ),
  85. // 动态的 收藏数
  86. CollectionWidget(collectionNum: itemObj['collection_num'], isCollection: itemObj['isCollection']),
  87. ],
  88. ),
  89. ],
  90. );
  91. }
  92. }
  93. class CollectionWidget extends HookConsumerWidget {
  94. int collectionNum = 0;
  95. bool isCollection = false;
  96. CollectionWidget({
  97. Key? key,
  98. required this.collectionNum,
  99. required this.isCollection,
  100. }) : super(key: key);
  101. @override
  102. Widget build(BuildContext context, WidgetRef ref) {
  103. final collectionNumState = useState(collectionNum);
  104. final isCollectionState = useState(isCollection);
  105. return Container(
  106. width: 60,
  107. height: 30,
  108. alignment: Alignment.center,
  109. decoration: BoxDecoration(
  110. color: ColorUtils.string2Color('#E5E5E5'),
  111. borderRadius: BorderRadius.circular(15),
  112. ),
  113. child: Row(
  114. mainAxisAlignment: MainAxisAlignment.center,
  115. children: [
  116. MyTextView(
  117. '${collectionNumState.value}',
  118. textColor: ColorUtils.string2Color('#999999'),
  119. fontSize: 14,
  120. isFontRegular: true,
  121. ),
  122. MyLoadImage(
  123. isCollectionState.value? Assets.communityLikeActive: Assets.communityLike,
  124. width: 14,
  125. height: 14,
  126. )
  127. ]
  128. ).onTap((){
  129. // 点击 收餐/取消收藏
  130. Log.d("点击了收藏按钮");
  131. })
  132. );
  133. }
  134. }