garage_page.dart 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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:cs_resources/theme/app_colors_theme.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:auto_route/auto_route.dart';
  7. import 'package:flutter/rendering.dart';
  8. import 'package:hooks_riverpod/hooks_riverpod.dart';
  9. import 'package:router/ext/auto_router_extensions.dart';
  10. import 'package:shared/utils/color_utils.dart';
  11. import 'package:shared/utils/log_utils.dart';
  12. import 'package:widgets/ext/ex_widget.dart';
  13. import 'package:widgets/my_appbar.dart';
  14. import 'package:widgets/my_load_image.dart';
  15. import 'package:widgets/my_text_view.dart';
  16. import 'package:widgets/widget_export.dart';
  17. import '../../components/newfeed_card_header.dart';
  18. import '../../router/page/community_page_router.dart';
  19. import '../garage/garage_vm.dart';
  20. import 'garage_tabs.dart';
  21. import 'garage_vm.dart';
  22. @RoutePage()
  23. class GaragePage extends HookConsumerWidget {
  24. const GaragePage({Key? key}) : super(key: key);
  25. //启动当前页面
  26. static void startInstance({BuildContext? context}) {
  27. if (context != null) {
  28. context.router.push(const GaragePageRoute());
  29. } else {
  30. appRouter.push(const GaragePageRoute());
  31. }
  32. }
  33. Widget _buildTabsSection(BuildContext context, WidgetRef ref, tabsRouter){
  34. final vm = ref.read(garageVmProvider.notifier);
  35. return Container(
  36. width: double.infinity,
  37. padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  38. child: GarageTabs(
  39. key: UniqueKey(),
  40. tabsList: vm.state.tabsList,
  41. tabsRouter: tabsRouter,
  42. onClickAction:(activeTabIdx){
  43. vm.handlerChangeTab(activeTabIdx, tabsRouter);
  44. }
  45. ),
  46. );
  47. }
  48. Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
  49. return Container(
  50. height: 65.5,
  51. width: double.infinity,
  52. padding: const EdgeInsets.only(left: 20, right: 20),
  53. color: Colors.white,
  54. child: Row(
  55. children: [
  56. const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
  57. Expanded(
  58. child: Row(
  59. children: [
  60. Expanded(
  61. child: Container(
  62. // height: 65.5,
  63. // color: Colors.blue,
  64. child: MyTextView(
  65. "Sell Item",
  66. textColor: ColorUtils.string2Color('#000000'),
  67. fontSize: 15,
  68. marginLeft: 15,
  69. alignment: Alignment.centerLeft,
  70. textAlign: TextAlign.left,
  71. backgroundColor: ColorUtils.string2Color('#ffffff'),
  72. maxLines: 1,
  73. isFontMedium: true,
  74. ),
  75. ),
  76. ),
  77. const MyAssetImage(
  78. Assets.communityCamera,
  79. width: 21,
  80. height: 16.5,
  81. ),
  82. ],
  83. ).onTap((){
  84. vm.handlerGotoPost(context);
  85. }),
  86. ),
  87. ],
  88. ),
  89. );
  90. }
  91. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  92. return Container(
  93. width: double.infinity,
  94. // padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  95. color: Colors.yellow,
  96. child: Container(
  97. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  98. color: Colors.white,
  99. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  100. height: 280,
  101. child: Column(
  102. mainAxisAlignment: MainAxisAlignment.center,
  103. crossAxisAlignment: CrossAxisAlignment.start,
  104. children: [
  105. // 卡片头部(头像 标题 时间)
  106. NewsFeedCardHeader(
  107. key: UniqueKey(),
  108. title: item['title'],
  109. avator: item['avator'],
  110. time: item['time'],
  111. ),
  112. const SizedBox(height: 15),
  113. // 卡片中间 (文字和图片)
  114. Expanded(
  115. child: NewsFeedCardContent(
  116. key: UniqueKey(),
  117. content: item['content'],
  118. imageUrls: item['imageUrls'],
  119. ),
  120. ),
  121. const SizedBox(height: 26),
  122. // // 卡片底部 (点赞 评论 分享)
  123. NewsFeedCardFooter(
  124. key: UniqueKey(),
  125. isLike: item['isLike'],
  126. ),
  127. ]
  128. ),
  129. )
  130. );
  131. }
  132. Widget _buildNewsFeedList(BuildContext context, WidgetRef ref, vm){
  133. final itemList = vm.state.list?? [];
  134. if(itemList.isEmpty){
  135. return const Center(child: Text('No Data'));
  136. }else {
  137. List itemsList = vm.state.list.toList();
  138. return ListView.builder(
  139. key: UniqueKey(),
  140. itemCount: itemsList.length,
  141. itemBuilder: (context, index) {
  142. return _buildNewsItem(context, ref, itemsList[index], vm);
  143. },
  144. );
  145. }
  146. }
  147. @override
  148. Widget build(BuildContext context, WidgetRef ref) {
  149. final vm = ref.read(garageVmProvider.notifier);
  150. return Scaffold(
  151. appBar: MyAppBar.searchAppBar(
  152. context,
  153. backgroundColor: context.appColors.whiteBG,
  154. actions: [
  155. IconButton(
  156. icon: const Icon(Icons.search),
  157. onPressed: () {
  158. // do something
  159. },
  160. ),
  161. ],
  162. ),
  163. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  164. body: NestedScrollView(
  165. headerSliverBuilder: (context, innerBoxIsScrolled) {
  166. return [
  167. SliverToBoxAdapter(
  168. child: Consumer(
  169. builder: (context, ref, _) {
  170. return _buildTopSection(context, ref, vm);
  171. },
  172. ),
  173. ),
  174. ];
  175. },
  176. body: NotificationListener<ScrollNotification>(
  177. onNotification: (ScrollNotification notification) {
  178. // 是否拦截滚动 false 表示不拦截通知
  179. // return _isPreventScroll(notification, ref);
  180. return false;
  181. },
  182. child: AutoTabsRouter.pageView(
  183. key: UniqueKey(),
  184. routes: const [
  185. ForsalePageRoute(),
  186. ForrentPageRoute(),
  187. ],
  188. builder: (context, child, animation) {
  189. final tabsRouter = AutoTabsRouter.of(context);
  190. return Column(
  191. children: [
  192. // garagesale tab 分类 (For sale For Rent)
  193. _buildTabsSection(context, ref, tabsRouter),
  194. // 发布 garage sale 组件
  195. _buildPostSection(context, ref, vm),
  196. Expanded(
  197. child: child,
  198. )
  199. ],
  200. );
  201. },
  202. ),
  203. ),
  204. ),
  205. );
  206. }
  207. Widget _buildTopSection(BuildContext context, WidgetRef ref, vm) {
  208. final topSectionsData = vm.topSectionsData;
  209. int curTagIdx = 1;
  210. return Container(
  211. color: Colors.white,
  212. padding: const EdgeInsets.only(top: 30, bottom: 30),
  213. child: Center(
  214. child: Row(
  215. mainAxisAlignment: MainAxisAlignment.center,
  216. crossAxisAlignment: CrossAxisAlignment.center,
  217. children: List.generate(topSectionsData.length, (index) {
  218. final item = topSectionsData[index];
  219. return Flexible(
  220. flex: 1,
  221. child: Column(
  222. children: [
  223. Container(
  224. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  225. height: 70,
  226. decoration: BoxDecoration(
  227. // color: currentTabIdx == index ? ColorUtils.string2Color('#E6F2FF') : Colors.white,
  228. shape: BoxShape.circle, // 设置为圆形
  229. boxShadow: index == curTagIdx ? [
  230. BoxShadow(
  231. color: context.appColors.tabLightBlueShadow, // 设置阴影颜色
  232. blurRadius: 5, // 设置模糊半径
  233. spreadRadius: 0.05, // 控制阴影扩散
  234. offset: const Offset(0, 4), // 设置阴影偏移量
  235. ), ] : [],// 未选中时无阴影,
  236. ),
  237. child: MyAssetImage(
  238. item['icon'],
  239. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  240. height: 70,
  241. ).onTap(() {
  242. vm.handlerChangeCommunityType(context,index);
  243. },
  244. type: ClickType.throttle,
  245. ),
  246. ),
  247. SizedBox.fromSize(size: const Size(0, 9)),
  248. MyTextView(
  249. item['title'],
  250. fontSize: 15,
  251. textColor: index == curTagIdx ? ColorUtils.string2Color('#4161D0'):Colors.black,
  252. textAlign: TextAlign.center,
  253. isFontMedium: true,
  254. ),
  255. ],
  256. ),
  257. ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
  258. }),
  259. ),
  260. ),
  261. );
  262. }
  263. }