garage_page.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. @override
  133. Widget build(BuildContext context, WidgetRef ref) {
  134. final vm = ref.read(garageVmProvider.notifier);
  135. return Scaffold(
  136. appBar: MyAppBar.searchAppBar(
  137. context,
  138. backgroundColor: context.appColors.whiteBG,
  139. actions: [
  140. IconButton(
  141. icon: const Icon(Icons.search),
  142. onPressed: () {
  143. // do something
  144. vm.handlerChooseCategory(context);
  145. },
  146. ),
  147. ],
  148. ),
  149. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  150. body: NestedScrollView(
  151. headerSliverBuilder: (context, innerBoxIsScrolled) {
  152. return [
  153. SliverToBoxAdapter(
  154. child: Consumer(
  155. builder: (context, ref, _) {
  156. return _buildTopSection(context, ref, vm);
  157. },
  158. ),
  159. ),
  160. ];
  161. },
  162. body: NotificationListener<ScrollNotification>(
  163. onNotification: (ScrollNotification notification) {
  164. // 是否拦截滚动 false 表示不拦截通知
  165. // return _isPreventScroll(notification, ref);
  166. return false;
  167. },
  168. child: AutoTabsRouter.pageView(
  169. key: UniqueKey(),
  170. routes: const [
  171. ForsalePageRoute(),
  172. ForrentPageRoute(),
  173. ],
  174. builder: (context, child, animation) {
  175. final tabsRouter = AutoTabsRouter.of(context);
  176. return Column(
  177. mainAxisSize: MainAxisSize.max,
  178. children: [
  179. // garagesale tab 分类 (For sale For Rent)
  180. _buildTabsSection(context, ref, tabsRouter),
  181. // 发布 garage sale 组件
  182. _buildPostSection(context, ref, vm),
  183. Expanded(
  184. child: child,
  185. )
  186. ],
  187. );
  188. },
  189. ),
  190. ),
  191. ),
  192. // body: AutoTabsRouter.pageView(
  193. // key: UniqueKey(),
  194. // routes: const [
  195. // ForsalePageRoute(),
  196. // ForrentPageRoute(),
  197. // ],
  198. // builder: (context, child, animation) {
  199. // final tabsRouter = AutoTabsRouter.of(context);
  200. // return Column(
  201. // mainAxisSize: MainAxisSize.max,
  202. // children: [
  203. // // garagesale tab 分类 (For sale For Rent)
  204. // _buildTabsSection(context, ref, tabsRouter),
  205. // // 发布 garage sale 组件
  206. // _buildPostSection(context, ref, vm),
  207. // Expanded(
  208. // child: child,
  209. // )
  210. // ],
  211. // );
  212. // },
  213. // )
  214. );
  215. }
  216. Widget _buildTopSection(BuildContext context, WidgetRef ref, vm) {
  217. final topSectionsData = vm.topSectionsData;
  218. int curTagIdx = 1;
  219. return Container(
  220. color: Colors.white,
  221. padding: const EdgeInsets.only(top: 23, bottom: 30),
  222. child: Center(
  223. child: Row(
  224. mainAxisSize: MainAxisSize.max,
  225. mainAxisAlignment: MainAxisAlignment.center,
  226. crossAxisAlignment: CrossAxisAlignment.center,
  227. children: List.generate(topSectionsData.length, (index) {
  228. final item = topSectionsData[index];
  229. return Flexible(
  230. flex: 1,
  231. child: Column(
  232. children: [
  233. Container(
  234. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  235. height: 70,
  236. decoration: BoxDecoration(
  237. // color: currentTabIdx == index ? ColorUtils.string2Color('#E6F2FF') : Colors.white,
  238. shape: BoxShape.circle, // 设置为圆形
  239. boxShadow: index == curTagIdx ? [
  240. BoxShadow(
  241. color: context.appColors.tabLightBlueShadow, // 设置阴影颜色
  242. blurRadius: 5, // 设置模糊半径
  243. spreadRadius: 0.05, // 控制阴影扩散
  244. offset: const Offset(0, 4), // 设置阴影偏移量
  245. ), ] : [],// 未选中时无阴影,
  246. ),
  247. child: MyAssetImage(
  248. item['icon'],
  249. width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
  250. height: 70,
  251. ).onTap(() {
  252. vm.handlerChangeCommunityType(context,index);
  253. },
  254. type: ClickType.throttle,
  255. ),
  256. ),
  257. SizedBox.fromSize(size: const Size(0, 9)),
  258. MyTextView(
  259. item['title'],
  260. fontSize: 15,
  261. textColor: index == curTagIdx ? ColorUtils.string2Color('#4161D0'):Colors.black,
  262. textAlign: TextAlign.center,
  263. isFontMedium: true,
  264. ),
  265. ],
  266. ),
  267. ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
  268. }),
  269. ),
  270. ),
  271. );
  272. }
  273. }