property_vm.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:riverpod_annotation/riverpod_annotation.dart';
  4. import 'package:shared/utils/log_utils.dart';
  5. import '../../ioan/page/property_ioan_page.dart';
  6. import '../../news/page/property_news_page.dart';
  7. import '../../rent/page/property_rent_page.dart';
  8. import '../../sale/page/property_sale_page.dart';
  9. part 'property_vm.g.dart';
  10. class PropertyVmState {
  11. List<Map<String, dynamic>> topSectionsData;
  12. PropertyVmState({
  13. required this.topSectionsData,
  14. });
  15. PropertyVmState CopyWith({
  16. required List<Map<String, dynamic>> topSectionsData,
  17. }){
  18. return PropertyVmState(
  19. topSectionsData: topSectionsData ?? this.topSectionsData,
  20. );
  21. }
  22. }
  23. @riverpod
  24. class PropertyVm extends _$PropertyVm {
  25. get topSectionsData => state.topSectionsData;
  26. PropertyVmState initState() {
  27. return PropertyVmState(
  28. topSectionsData: [
  29. {
  30. "title": "Sale",
  31. "icon": Assets.propertySale2x,
  32. "pageStartInstanceFn": PropertySalePage.startInstance,
  33. "page": const PropertySalePage(),
  34. },
  35. {
  36. "title": "Rent",
  37. "icon": Assets.propertyRent2x,
  38. "pageStartInstanceFn": PropertyRentPage.startInstance,
  39. "page": const PropertyRentPage(),
  40. },
  41. {
  42. "title": "Ioan",
  43. "icon": Assets.propertyIoan2x,
  44. "pageStartInstanceFn": PropertyIoanPage.startInstance,
  45. "page": const PropertyIoanPage(),
  46. },
  47. {
  48. "title": "News",
  49. "icon": Assets.propertyNews2x,
  50. "pageStartInstanceFn": PropertyNewsPage.startInstance,
  51. "page": const PropertyNewsPage(),
  52. }
  53. ],
  54. );
  55. }
  56. @override
  57. PropertyVmState build(){
  58. final state = initState();
  59. return state;
  60. }
  61. // 页面切换
  62. switchPage(int index, context){
  63. final _topSectionsData = state.topSectionsData;
  64. Log.d("当前页面${_topSectionsData[index]['pageStartInstanceFn']}");
  65. final pageStartInstanceFn = _topSectionsData[index]['pageStartInstanceFn'] as Function({BuildContext? context});
  66. pageStartInstanceFn(context:context);
  67. }
  68. }