garagesale_page.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import 'package:cpt_community/components/custom_tabs.dart';
  2. import 'package:cpt_community/components/newsfeed_card_content.dart';
  3. import 'package:cpt_community/components/newsfeed_card_footer.dart';
  4. import 'package:cs_resources/generated/assets.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:auto_route/auto_route.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 'garagesale_vm.dart';
  18. @RoutePage()
  19. class GaragesalePage extends HookConsumerWidget {
  20. const GaragesalePage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const GaragesalePageRoute());
  25. } else {
  26. appRouter.push(const GaragesalePageRoute());
  27. }
  28. }
  29. Widget _buildTabsSection(BuildContext context, WidgetRef ref, vm){
  30. print("222222222222222222${vm.state.tabsList}");
  31. return Container(
  32. width: double.infinity,
  33. padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  34. child: CustomTabs(
  35. key: UniqueKey(),
  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. Expanded(
  149. child: EasyRefresh(
  150. // 上拉加载
  151. onLoad: () async{
  152. Log.d("----onLoad");
  153. vm.onLoadData();
  154. },
  155. // 下拉刷新
  156. onRefresh: () async{
  157. Log.d("----onRefresh");
  158. vm.refreshListData();
  159. },
  160. child: _buildNesFeedList(context, ref, vm),
  161. ),
  162. )
  163. ],
  164. ),
  165. );
  166. }
  167. }