community_vm.dart 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. late PageController _pageController;
  16. get topSectionsData => state.topSectionsData;
  17. CommunityVmState initState() {
  18. return CommunityVmState(
  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. handlerChangeCommunityType(BuildContext context, int index){
  38. if(index == 1){
  39. Log.d("去往garage 页面");
  40. // 跳转到 garage sale 页面
  41. GaragePage.startInstance(context: context);
  42. // AutoRouter.of(context).push(const GaragePageRoute());
  43. }
  44. }
  45. // 点击发布的按钮 跳转到发布的页面
  46. void handlerGotoPost(context){
  47. // ComponentServiceManager().communityService.startCommunityPage();
  48. // AutoRouter.of(context).pushNamed(RouterPath.newsFeedPost);
  49. NewsfeedPostPage.startInstance();
  50. }
  51. }