import 'package:cs_resources/generated/assets.dart'; import 'package:flutter/cupertino.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:shared/utils/log_utils.dart'; import '../../ioan/page/property_ioan_page.dart'; import '../../news/page/property_news_page.dart'; import '../../rent/page/property_rent_page.dart'; import '../../sale/page/property_sale_page.dart'; part 'property_vm.g.dart'; class PropertyVmState { List> topSectionsData; PropertyVmState({ required this.topSectionsData, }); PropertyVmState CopyWith({ required List> topSectionsData, }){ return PropertyVmState( topSectionsData: topSectionsData ?? this.topSectionsData, ); } } @riverpod class PropertyVm extends _$PropertyVm { get topSectionsData => state.topSectionsData; PropertyVmState initState() { return PropertyVmState( topSectionsData: [ { "title": "Sale", "icon": Assets.propertySale2x, "pageStartInstanceFn": PropertySalePage.startInstance, "page": const PropertySalePage(), }, { "title": "Rent", "icon": Assets.propertyRent2x, "pageStartInstanceFn": PropertyRentPage.startInstance, "page": const PropertyRentPage(), }, { "title": "Ioan", "icon": Assets.propertyIoan2x, "pageStartInstanceFn": PropertyIoanPage.startInstance, "page": const PropertyIoanPage(), }, { "title": "News", "icon": Assets.propertyNews2x, "pageStartInstanceFn": PropertyNewsPage.startInstance, "page": const PropertyNewsPage(), } ], ); } @override PropertyVmState build(){ final state = initState(); return state; } // 页面切换 switchPage(int index, context){ final _topSectionsData = state.topSectionsData; Log.d("当前页面${_topSectionsData[index]['pageStartInstanceFn']}"); final pageStartInstanceFn = _topSectionsData[index]['pageStartInstanceFn'] as Function({BuildContext? context}); pageStartInstanceFn(context:context); } }