community_vm.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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:shared/utils/log_utils.dart';
  6. import 'community_state.dart';
  7. import '../garagesale/garagesale_page.dart';
  8. import '../newsfeed/newsfeed_page.dart';
  9. part 'community_vm.g.dart';
  10. @riverpod
  11. class CommunityVm extends _$CommunityVm {
  12. get topSectionsData => state.topSectionsData;
  13. CommunityVmState initState() {
  14. return CommunityVmState();
  15. }
  16. @override
  17. CommunityVmState build(){
  18. final state = initState();
  19. Log.d("--------------------------build---------------------");
  20. return state;
  21. }
  22. // 设置当前的 tabsRouter 和 pageController
  23. Future setTabsRouterAndPageController(dynamic tabsRouter, dynamic pageController) async{
  24. Log.d("setTabsRouterAndPageController---: $tabsRouter");
  25. state = await state.copyWith(tabsRouter: tabsRouter, pageController: pageController,curIdx: tabsRouter.activeIndex);
  26. }
  27. Future setCurrentUseTag(int useTag) async {
  28. state = await state.copyWith(useTag: useTag, curIdx: useTag);
  29. Log.d("useTag----: $useTag");
  30. }
  31. // 页面切换
  32. switchPage(int index,int useTag,BuildContext? context, [bool? isFirstInitSwitch] ){
  33. if(state.curIdx != index){
  34. state = state.copyWith(curIdx: index, useTag: useTag);
  35. final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
  36. // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
  37. final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
  38. pageStartInstanceFn(context:context);
  39. }else {
  40. if(isFirstInitSwitch??false){
  41. final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
  42. // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
  43. final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
  44. pageStartInstanceFn(context:context);
  45. }
  46. }
  47. }
  48. }