garage_page.dart 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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: MyTextView(
  59. "Sell Item",
  60. textColor: ColorUtils.string2Color('#000000'),
  61. fontSize: 15,
  62. marginLeft: 15,
  63. alignment: Alignment.centerLeft,
  64. textAlign: TextAlign.left,
  65. backgroundColor: ColorUtils.string2Color('#ffffff'),
  66. maxLines: 1,
  67. isFontMedium: true,
  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. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  82. return Container(
  83. width: double.infinity,
  84. // padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  85. color: Colors.yellow,
  86. child: Container(
  87. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  88. color: Colors.white,
  89. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  90. height: 280,
  91. child: Column(
  92. mainAxisAlignment: MainAxisAlignment.center,
  93. crossAxisAlignment: CrossAxisAlignment.start,
  94. children: [
  95. // 卡片头部(头像 标题 时间)
  96. NewsFeedCardHeader(
  97. key: UniqueKey(),
  98. title: item['title'],
  99. avator: item['avator'],
  100. time: item['time'],
  101. ),
  102. const SizedBox(height: 15),
  103. // 卡片中间 (文字和图片)
  104. Expanded(
  105. child: NewsFeedCardContent(
  106. key: UniqueKey(),
  107. content: item['content'],
  108. imageUrls: item['imageUrls'],
  109. ),
  110. ),
  111. const SizedBox(height: 26),
  112. // // 卡片底部 (点赞 评论 分享)
  113. NewsFeedCardFooter(
  114. key: UniqueKey(),
  115. isLike: item['isLike'],
  116. ),
  117. ]
  118. ),
  119. )
  120. );
  121. }
  122. @override
  123. Widget build(BuildContext context, WidgetRef ref) {
  124. final vm = ref.read(garageVmProvider.notifier);
  125. return Scaffold(
  126. appBar: MyAppBar.searchAppBar(
  127. context,
  128. backgroundColor: context.appColors.whiteBG,
  129. actions: [
  130. IconButton(
  131. icon: const Icon(Icons.search),
  132. onPressed: () {
  133. // do something
  134. vm.handlerChooseCategory(context);
  135. },
  136. ),
  137. ],
  138. ),
  139. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  140. body: NestedScrollView(
  141. headerSliverBuilder: (context, innerBoxIsScrolled) {
  142. return [
  143. SliverToBoxAdapter(
  144. child: Consumer(
  145. builder: (context, ref, _) {
  146. return _buildTopSection(context, ref, vm);
  147. },
  148. ),
  149. ),
  150. ];
  151. },
  152. body: NotificationListener<ScrollNotification>(
  153. onNotification: (ScrollNotification notification) {
  154. // 是否拦截滚动 false 表示不拦截通知
  155. // return _isPreventScroll(notification, ref);
  156. return false;
  157. },
  158. child: AutoTabsRouter.pageView(
  159. key: UniqueKey(),
  160. routes: const [
  161. ForsalePageRoute(),
  162. ForrentPageRoute(),
  163. ],
  164. builder: (context, child, animation) {
  165. final tabsRouter = AutoTabsRouter.of(context);
  166. return Column(
  167. mainAxisSize: MainAxisSize.max,
  168. children: [
  169. // garagesale tab 分类 (For sale For Rent)
  170. _buildTabsSection(context, ref, tabsRouter),
  171. // 发布 garage sale 组件
  172. _buildPostSection(context, ref, vm),
  173. Expanded(
  174. child: child,
  175. )
  176. ],
  177. );
  178. },
  179. ),
  180. ),
  181. ),
  182. // body: 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. // mainAxisSize: MainAxisSize.max,
  192. // children: [
  193. // // garagesale tab 分类 (For sale For Rent)
  194. // _buildTabsSection(context, ref, tabsRouter),
  195. // // 发布 garage sale 组件
  196. // _buildPostSection(context, ref, vm),
  197. // Expanded(
  198. // child: child,
  199. // )
  200. // ],
  201. // );
  202. // },
  203. // )
  204. );
  205. }
  206. Widget _buildTopSection(BuildContext context, WidgetRef ref, vm) {
  207. final topSectionsData = vm.topSectionsData;
  208. int curTagIdx = 1;
  209. return Container(
  210. color: context.appColors.whiteBG,
  211. padding: const EdgeInsets.only(top: 23, bottom: 30),
  212. child: Center(
  213. child: Row(
  214. mainAxisSize: MainAxisSize.max,
  215. mainAxisAlignment: MainAxisAlignment.center,
  216. crossAxisAlignment: CrossAxisAlignment.center,
  217. children: List.generate(topSectionsData.length, (index) {
  218. final item = topSectionsData[index];
  219. return Column(
  220. children: [
  221. Container(
  222. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  223. height: 70,
  224. decoration: BoxDecoration(
  225. // color: currentTabIdx == index ? ColorUtils.string2Color('#E6F2FF') : Colors.white,
  226. shape: BoxShape.circle, // 设置为圆形
  227. boxShadow: index == curTagIdx ? [
  228. BoxShadow(
  229. color: context.appColors.tabLightBlueShadow, // 设置阴影颜色
  230. blurRadius: 5, // 设置模糊半径
  231. spreadRadius: 0.05, // 控制阴影扩散
  232. offset: const Offset(0, 4), // 设置阴影偏移量
  233. ), ] : [],// 未选中时无阴影,
  234. ),
  235. child: MyAssetImage(
  236. item['icon'],
  237. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  238. height: 70,
  239. ).onTap(() {
  240. vm.handlerChangeCommunityType(context,index);
  241. },
  242. type: ClickType.throttle,
  243. ),
  244. ),
  245. SizedBox.fromSize(size: const Size(0, 9)),
  246. MyTextView(
  247. item['title'],
  248. fontSize: 15,
  249. textColor: index == curTagIdx ? ColorUtils.string2Color('#4161D0'):Colors.black,
  250. textAlign: TextAlign.center,
  251. isFontMedium: true,
  252. ),
  253. ],
  254. ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
  255. }),
  256. ),
  257. ),
  258. );
  259. }
  260. }