community_vm.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // 页面切换
  23. switchPage(int index,BuildContext? context, [bool? isFirstInitSwitch] ){
  24. if(state.curIdx != index){
  25. state = state.copyWith(curIdx: index);
  26. final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
  27. // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
  28. final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
  29. pageStartInstanceFn(context:context);
  30. }else {
  31. if(isFirstInitSwitch??false){
  32. final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
  33. // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
  34. final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
  35. pageStartInstanceFn(context:context);
  36. }
  37. }
  38. }
  39. }