garagesale_page.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import 'package:cpt_community/components/newsfeed_card_content.dart';
  2. import 'package:cpt_community/components/newsfeed_card_footer.dart';
  3. import 'package:cs_resources/generated/assets.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.dart';
  6. import 'package:flutter/rendering.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:shared/utils/color_utils.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 'package:widgets/widget_export.dart';
  15. import '../../components/newfeed_card_header.dart';
  16. import '../../router/page/community_page_router.dart';
  17. import '../community/community_vm.dart';
  18. import 'garagesale_tabs.dart';
  19. import 'garagesale_vm.dart';
  20. @RoutePage()
  21. class GaragesalePage extends HookConsumerWidget {
  22. const GaragesalePage({Key? key}) : super(key: key);
  23. //启动当前页面
  24. static void startInstance({BuildContext? context}) {
  25. if (context != null) {
  26. context.router.push(const GaragesalePageRoute());
  27. } else {
  28. appRouter.push(const GaragesalePageRoute());
  29. }
  30. }
  31. Widget _buildTabsSection(BuildContext context, WidgetRef ref, vm){
  32. return Container(
  33. width: double.infinity,
  34. padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  35. child: GaragesaleTabs(
  36. key: ValueKey(vm.state.activeIndex),
  37. tabsList: vm.state.tabsList,
  38. ),
  39. );
  40. }
  41. Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
  42. return Container(
  43. height: 65.5,
  44. width: double.infinity,
  45. padding: const EdgeInsets.only(left: 20, right: 20),
  46. color: Colors.white,
  47. child: Row(
  48. children: [
  49. const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
  50. Expanded(
  51. child: Row(
  52. children: [
  53. Expanded(
  54. child: Container(
  55. // height: 65.5,
  56. // color: Colors.blue,
  57. child: MyTextView(
  58. "Sell Item",
  59. textColor: ColorUtils.string2Color('#000000'),
  60. fontSize: 15,
  61. marginLeft: 15,
  62. alignment: Alignment.centerLeft,
  63. textAlign: TextAlign.left,
  64. backgroundColor: ColorUtils.string2Color('#ffffff'),
  65. maxLines: 1,
  66. isFontMedium: true,
  67. ),
  68. ),
  69. ),
  70. const MyAssetImage(
  71. Assets.communityCamera,
  72. width: 21,
  73. height: 16.5,
  74. ),
  75. ],
  76. ).onTap((){
  77. vm.handlerGotoPost(context);
  78. }),
  79. ),
  80. ],
  81. ),
  82. );
  83. }
  84. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  85. return Container(
  86. width: double.infinity,
  87. // padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  88. color: Colors.yellow,
  89. child: Container(
  90. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  91. color: Colors.white,
  92. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  93. height: 280,
  94. child: Column(
  95. mainAxisAlignment: MainAxisAlignment.center,
  96. crossAxisAlignment: CrossAxisAlignment.start,
  97. children: [
  98. // 卡片头部(头像 标题 时间)
  99. NewsFeedCardHeader(
  100. key: UniqueKey(),
  101. title: item['title'],
  102. avator: item['avator'],
  103. time: item['time'],
  104. ),
  105. const SizedBox(height: 15),
  106. // 卡片中间 (文字和图片)
  107. Expanded(
  108. child: NewsFeedCardContent(
  109. key: UniqueKey(),
  110. content: item['content'],
  111. imageUrls: item['imageUrls'],
  112. ),
  113. ),
  114. const SizedBox(height: 26),
  115. // // 卡片底部 (点赞 评论 分享)
  116. NewsFeedCardFooter(
  117. key: UniqueKey(),
  118. isLike: item['isLike'],
  119. ),
  120. ]
  121. ),
  122. )
  123. );
  124. }
  125. Widget _buildNesFeedList(BuildContext context, WidgetRef ref, vm){
  126. final itemList = vm.state.list?? [];
  127. if(itemList.isEmpty){
  128. return const Center(child: Text('No Data'));
  129. }else {
  130. List itemsList = vm.state.list.toList();
  131. return ListView.builder(
  132. key: UniqueKey(),
  133. itemCount: itemsList.length,
  134. itemBuilder: (context, index) {
  135. return _buildNewsItem(context, ref, itemsList[index], vm);
  136. },
  137. );
  138. }
  139. }
  140. @override
  141. Widget build(BuildContext context, WidgetRef ref) {
  142. final vm = ref.read(garagesaleVmProvider.notifier);
  143. return Scaffold(
  144. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  145. body: Column(
  146. children: [
  147. // tab 分类 (For sale For Rent)
  148. _buildTabsSection(context, ref, vm),
  149. // 发布组件
  150. _buildPostSection(context, ref, vm),
  151. NotificationListener<ScrollNotification>(
  152. onNotification: (ScrollNotification notification) {
  153. // 检查当前页面是否是可见的
  154. bool isDownOrUp = notification.metrics.axis == Axis.vertical;
  155. if (notification is UserScrollNotification) {
  156. // 检查滚动方向
  157. switch (notification.direction) {
  158. case ScrollDirection.forward:
  159. print('Scrolling down');
  160. break;
  161. case ScrollDirection.reverse:
  162. print('Scrolling up');
  163. break;
  164. case ScrollDirection.idle:
  165. print('Scrolling stopped');
  166. break;
  167. }
  168. } else if (notification is ScrollUpdateNotification) {
  169. // 检查滚动位置变化
  170. double currentScrollPosition = notification.metrics.pixels;
  171. double maxScrollExtent = notification.metrics.maxScrollExtent;
  172. // 判断是否满足某个条件
  173. if (currentScrollPosition > 0 && currentScrollPosition < maxScrollExtent) {
  174. print('Current scroll position: $currentScrollPosition');
  175. // 在这里添加你的条件判断逻辑
  176. }
  177. // 只有当上下滚动时才拦截通知
  178. if (notification.metrics.axis == Axis.vertical) {
  179. final tabsRouter = ref.watch(communityVmProvider).tabsRouter;
  180. final curUseTag = ref.watch(communityVmProvider).useTag;
  181. if(curUseTag != 1 ){
  182. // 非当前 页面都阻止滚动
  183. return true; // 返回 true 表示已处理通知
  184. }
  185. }
  186. }
  187. return false; // 返回 false 表示不拦截通知
  188. },
  189. child: Expanded(
  190. child: EasyRefresh(
  191. // 上拉加载
  192. onLoad: () async{
  193. Log.d("----onLoad");
  194. vm.onLoadData();
  195. },
  196. // 下拉刷新
  197. onRefresh: () async{
  198. Log.d("----onRefresh");
  199. vm.refreshListData();
  200. },
  201. child: _buildNesFeedList(context, ref, vm),
  202. ),
  203. ),
  204. )
  205. ],
  206. ),
  207. );
  208. }
  209. }