1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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<Map<String, dynamic>> topSectionsData;
- PropertyVmState({
- required this.topSectionsData,
- });
- PropertyVmState CopyWith({
- required List<Map<String, dynamic>> 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);
- }
- }
|