property_vm.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.dart';
  12. import '../page/property_page_state.dart';
  13. part 'property_vm.g.dart';
  14. @riverpod
  15. class PropertyVm extends _$PropertyVm {
  16. get topSectionsData => state.topSectionsData;
  17. Map<String, dynamic> _newsQueryMap = {
  18. "isCollection": false,
  19. };
  20. PropertyVmState initState() {
  21. return PropertyVmState();
  22. }
  23. @override
  24. PropertyVmState build(){
  25. final state = initState();
  26. Log.d("--------------------------build---------------------");
  27. // 初始时导航到子路由
  28. WidgetsBinding.instance.addPostFrameCallback((_) {
  29. });
  30. return state;
  31. }
  32. tabsRouterChange(){
  33. // 设置当前导航栏的 图标 等状态
  34. Log.d("----tabsRouterChange---${tabsRouterKey.currentState?.controller?.activeIndex}-");
  35. state = state.copyWith(currentPageViewIdx: tabsRouterKey.currentState?.controller?.activeIndex ?? 0);
  36. }
  37. // 点击了导航的 搜索 进行筛选
  38. handlerCollectionFilter(BuildContext? context, bool isCollection ){
  39. _newsQueryMap['isCollection'] = isCollection;
  40. // 重新加载数据
  41. final newsPageVm = ref.read(propertyNewsVmProvider.notifier);
  42. newsPageVm..changeQueryMap({
  43. "isCollection": _newsQueryMap['isCollection'],
  44. })..retryRequest();
  45. }
  46. }