property_vm.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import 'package:cpt_property/modules/news/vm/property_news_vm.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 '../../ioan/property_ioan_page.dart';
  8. import '../../news/page/property_news_page.dart';
  9. import '../../rent/page/property_rent_page.dart';
  10. import '../../sale/page/property_sale_page.dart';
  11. import '../page/property_page_state.dart';
  12. part 'property_vm.g.dart';
  13. @riverpod
  14. class PropertyVm extends _$PropertyVm {
  15. get topSectionsData => state.topSectionsData;
  16. Map<String, dynamic> _newsQueryMap = {
  17. "isCollection": false,
  18. };
  19. PropertyVmState initState() {
  20. return PropertyVmState();
  21. }
  22. @override
  23. PropertyVmState build(){
  24. final state = initState();
  25. Log.d("--------------------------build---------------------");
  26. // 初始时导航到子路由
  27. WidgetsBinding.instance.addPostFrameCallback((_) {
  28. });
  29. return state;
  30. }
  31. // 页面切换
  32. switchPage(int index,BuildContext? context, [bool? isFirstInitSwitch] ){
  33. if(state.curIdx != index){
  34. state = state.copyWith(curIdx: index);
  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. // 点击了导航的 搜索 进行筛选
  49. handlerCollectionFilter(BuildContext? context, bool isCollection ){
  50. _newsQueryMap['isCollection'] = isCollection;
  51. // 重新加载数据
  52. final newsPageVm = ref.read(propertyNewsVmProvider.notifier);
  53. newsPageVm..changeQueryMap({
  54. "isCollection": _newsQueryMap['isCollection'],
  55. })..retryRequest();
  56. }
  57. }