community_vm.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import 'package:cpt_community/modules/garage/garage_page.dart';
  2. import 'package:cpt_community/router/page/community_page_router.dart';
  3. import 'package:cs_resources/generated/assets.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  6. import 'package:riverpod_annotation/riverpod_annotation.dart';
  7. import 'package:router/path/router_path.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:auto_route/auto_route.dart';
  10. import 'community_state.dart';
  11. import 'newsfeed_post/newsfeed_post_page.dart';
  12. part 'community_vm.g.dart';
  13. @riverpod
  14. class CommunityVm extends _$CommunityVm {
  15. get topSectionsData => state.topSectionsData;
  16. CommunityVmState initState() {
  17. return CommunityVmState(
  18. currentTabIndex: 0,
  19. tabsList: ["News", "Following", "For You"],
  20. );
  21. }
  22. @override
  23. CommunityVmState build(){
  24. final state = initState();
  25. // 第一帧渲染完成
  26. WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
  27. });
  28. Log.d("--------------------------build---------------------");
  29. return state;
  30. }
  31. // 切换tab
  32. handlerChangeTab(int index, tabsRouter) {
  33. tabsRouter.setActiveIndex(index);
  34. // state = state.copyWith(tabsRouter: tabsRouter ,activeTabIdx: index);
  35. Log.d("community_vm handlerChangeTab--index: $index");
  36. }
  37. // 设置当前的 tabsRouter 和 pageController
  38. setTabsRouterAndPageController(dynamic tabsRouter, dynamic pageController) {
  39. Log.d("setTabsRouterAndPageController---:$tabsRouter");
  40. state = state.copyWith(tabsRouter: tabsRouter ,pageController: pageController, currentTabIndex: tabsRouter.activeIndex);
  41. }
  42. handlerChangeCommunityType(BuildContext context, int index){
  43. if(index == 1){
  44. Log.d("去往garage 页面");
  45. // 跳转到 garage sale 页面
  46. GaragePage.startInstance(context: context);
  47. // AutoRouter.of(context).push(const GaragePageRoute());
  48. }
  49. }
  50. // 点击发布的按钮 跳转到发布的页面
  51. void handlerGotoPost(context){
  52. // ComponentServiceManager().communityService.startCommunityPage();
  53. // AutoRouter.of(context).pushNamed(RouterPath.newsFeedPost);
  54. NewsfeedPostPage.startInstance();
  55. }
  56. }