my_following_vm.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import 'package:cpt_community/modules/my_following/tabs_data.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  5. import 'package:riverpod_annotation/riverpod_annotation.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. import 'package:auto_route/auto_route.dart';
  8. import 'my_following_page.dart';
  9. import 'my_following_state.dart';
  10. part 'my_following_vm.g.dart';
  11. @riverpod
  12. class MyFollowingVm extends _$MyFollowingVm {
  13. MyFollowingState initState() {
  14. return MyFollowingState(
  15. currentPageViewIdx: 0,
  16. );
  17. }
  18. @override
  19. MyFollowingState build(){
  20. final state = initState();
  21. Log.d("--------------------------build---------------------");
  22. return state;
  23. }
  24. tabsRouterChange(){
  25. Log.d("----tabsRouterChange---${myFollowingPageTabsRouterKey.currentState?.controller?.activeIndex}-");
  26. state = state.copyWith(
  27. currentPageViewIdx: myFollowingPageTabsRouterKey.currentState?.controller?.activeIndex ?? 0
  28. );
  29. }
  30. // 切换tab
  31. handlerChangeTab(int tabIndex, TabsRouter? tabsRouter,) {
  32. tabsRouter = (tabsRouter?? myFollowingPageTabsRouterKey.currentState?.controller)!;
  33. tabsRouter.setActiveIndex(tabIndex);
  34. }
  35. // 设置当前tab
  36. setCurrentTabIndex(int activeTabIdx){
  37. state = state.copyWith(
  38. activeTabIdx: activeTabIdx,
  39. );
  40. }
  41. // 改变 follow 页面navigatorbar
  42. handlerChangeFollowPageNavbar(bool showSearchBar){
  43. WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
  44. if(showSearchBar){
  45. state = state.copyWith(
  46. followPageIsSearchBarStatus: true,
  47. );
  48. } else {
  49. state = state.copyWith(
  50. followPageIsSearchBarStatus: false,
  51. );
  52. }
  53. });
  54. }
  55. // 改变 follower 页面navigatorbar
  56. handlerChangeFollowerPageNavbar(bool showSearchBar){
  57. WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
  58. if(showSearchBar){
  59. state = state.copyWith(
  60. followerPageIsSearchBarStatus: true,
  61. );
  62. } else {
  63. state = state.copyWith(
  64. followerPageIsSearchBarStatus: false,
  65. );
  66. }
  67. });
  68. }
  69. // 更新 tab 的数字
  70. updateMyFollowingTabsNum(String code, int num, int activeTabIdx){
  71. if(code == tabsNamesData['Follower']){
  72. state = state.copyWith(
  73. followerCount: num,
  74. activeTabIdx: activeTabIdx,
  75. );
  76. } else if(code == tabsNamesData['Follow']){
  77. state = state.copyWith(
  78. followCount: num,
  79. activeTabIdx: activeTabIdx,
  80. );
  81. }
  82. }
  83. }