garagesale_page.dart 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. tabsList: vm.state.tabsList,
  37. ),
  38. );
  39. }
  40. Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
  41. return Container(
  42. height: 65.5,
  43. width: double.infinity,
  44. padding: const EdgeInsets.only(left: 20, right: 20),
  45. color: Colors.white,
  46. child: Row(
  47. children: [
  48. const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
  49. Expanded(
  50. child: Row(
  51. children: [
  52. Expanded(
  53. child: Container(
  54. // height: 65.5,
  55. // color: Colors.blue,
  56. child: MyTextView(
  57. "Sell Item",
  58. textColor: ColorUtils.string2Color('#000000'),
  59. fontSize: 15,
  60. marginLeft: 15,
  61. alignment: Alignment.centerLeft,
  62. textAlign: TextAlign.left,
  63. backgroundColor: ColorUtils.string2Color('#ffffff'),
  64. maxLines: 1,
  65. isFontMedium: true,
  66. ),
  67. ),
  68. ),
  69. const MyAssetImage(
  70. Assets.communityCamera,
  71. width: 21,
  72. height: 16.5,
  73. ),
  74. ],
  75. ).onTap((){
  76. vm.handlerGotoPost(context);
  77. }),
  78. ),
  79. ],
  80. ),
  81. );
  82. }
  83. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  84. return Container(
  85. width: double.infinity,
  86. // padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  87. color: Colors.yellow,
  88. child: Container(
  89. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  90. color: Colors.white,
  91. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  92. height: 280,
  93. child: Column(
  94. mainAxisAlignment: MainAxisAlignment.center,
  95. crossAxisAlignment: CrossAxisAlignment.start,
  96. children: [
  97. // 卡片头部(头像 标题 时间)
  98. NewsFeedCardHeader(
  99. title: item['title'],
  100. avator: item['avator'],
  101. time: item['time'],
  102. ),
  103. const SizedBox(height: 15),
  104. // 卡片中间 (文字和图片)
  105. Expanded(
  106. child: NewsFeedCardContent(
  107. content: item['content'],
  108. imageUrls: item['imageUrls'],
  109. ),
  110. ),
  111. const SizedBox(height: 26),
  112. // // 卡片底部 (点赞 评论 分享)
  113. NewsFeedCardFooter(
  114. isLike: item['isLike'],
  115. ),
  116. ]
  117. ),
  118. )
  119. );
  120. }
  121. Widget _buildNesFeedList(BuildContext context, WidgetRef ref, vm){
  122. // return Container(
  123. // height: 100,
  124. // color: Colors.blue,
  125. // );
  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. itemCount: itemsList.length,
  133. itemBuilder: (context, index) {
  134. return _buildNewsItem(context, ref, itemsList[index], vm);
  135. },
  136. );
  137. }
  138. }
  139. @override
  140. Widget build(BuildContext context, WidgetRef ref) {
  141. final vm = ref.read(garagesaleVmProvider.notifier);
  142. return Scaffold(
  143. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  144. body: Column(
  145. children: [
  146. _buildTabsSection(context, ref, vm),
  147. _buildPostSection(context, ref, vm),
  148. NotificationListener<ScrollNotification>(
  149. onNotification: (ScrollNotification notification) {
  150. // 检查当前页面是否是可见的
  151. bool isDownOrUp = notification.metrics.axis == Axis.vertical;
  152. if (notification is UserScrollNotification) {
  153. // 检查滚动方向
  154. switch (notification.direction) {
  155. case ScrollDirection.forward:
  156. print('Scrolling down');
  157. break;
  158. case ScrollDirection.reverse:
  159. print('Scrolling up');
  160. break;
  161. case ScrollDirection.idle:
  162. print('Scrolling stopped');
  163. break;
  164. }
  165. } else if (notification is ScrollUpdateNotification) {
  166. // 检查滚动位置变化
  167. double currentScrollPosition = notification.metrics.pixels;
  168. double maxScrollExtent = notification.metrics.maxScrollExtent;
  169. // 判断是否满足某个条件
  170. if (currentScrollPosition > 0 && currentScrollPosition < maxScrollExtent) {
  171. print('Current scroll position: $currentScrollPosition');
  172. // 在这里添加你的条件判断逻辑
  173. }
  174. // 只有当上下滚动时才拦截通知
  175. if (notification.metrics.axis == Axis.vertical) {
  176. final tabsRouter = ref.watch(communityVmProvider).tabsRouter;
  177. final curUseTag = ref.watch(communityVmProvider).useTag;
  178. if(curUseTag != 1 ){
  179. // 非当前 页面都阻止滚动
  180. return true; // 返回 true 表示已处理通知
  181. }
  182. }
  183. }
  184. return false; // 返回 false 表示不拦截通知
  185. },
  186. child: Expanded(
  187. child: EasyRefresh(
  188. // 上拉加载
  189. onLoad: () async{
  190. Log.d("----onLoad");
  191. vm.onLoadData();
  192. },
  193. // 下拉刷新
  194. onRefresh: () async{
  195. Log.d("----onRefresh");
  196. vm.refreshListData();
  197. },
  198. child: _buildNesFeedList(context, ref, vm),
  199. ),
  200. ),
  201. )
  202. ],
  203. ),
  204. );
  205. }
  206. }