community_vm.dart 2.4 KB

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