123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import 'package:cs_resources/generated/assets.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:plugin_platform/engine/toast/toast_engine.dart';
- import 'package:riverpod_annotation/riverpod_annotation.dart';
- import 'package:shared/utils/log_utils.dart';
- import '../../ioan/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;
- int? curIdx;
- PropertyVmState({
- List<Map<String, dynamic>>? topSectionsData,
- this.curIdx = 0,
- }) : topSectionsData = topSectionsData?? [
- {
- "title": "Ioan",
- "icon": Assets.propertyIoan,
- "pageStartInstanceFn": PropertyIoanPage.startInstance,
- "page": const PropertyIoanPage(),
- },
- {
- "title": "News",
- "icon": Assets.propertyNews,
- "pageStartInstanceFn": PropertyNewsPage.startInstance,
- "page": const PropertyNewsPage(),
- },
- {
- "title": "Sale",
- "icon": Assets.propertySale,
- "pageStartInstanceFn": PropertySalePage.startInstance,
- "page": const PropertySalePage(),
- },
- {
- "title": "Rent",
- "icon": Assets.propertyRent,
- "pageStartInstanceFn": PropertyRentPage.startInstance,
- "page": const PropertyRentPage(),
- },
- ];
- PropertyVmState copyWith({
- List<Map<String, dynamic>>? topSectionsData,
- int? curIdx = 0,
- }) {
- return PropertyVmState(
- topSectionsData: topSectionsData ?? this.topSectionsData,
- curIdx: curIdx ?? 0,
- );
- }
- }
- @riverpod
- class PropertyVm extends _$PropertyVm {
- get topSectionsData => state.topSectionsData;
- PropertyVmState initState() {
- return PropertyVmState();
- }
- @override
- PropertyVmState build(){
- final state = initState();
- Log.d("--------------------------build---------------------");
- // 初始时导航到子路由
- WidgetsBinding.instance.addPostFrameCallback((_) {
- switchPage(state.curIdx ?? 0, null, true);
- });
- return state;
- }
- // 页面切换
- switchPage(int index,BuildContext? context, [bool? isFirstInitSwitch] ){
- if(state.curIdx != index){
- state = state.copyWith(curIdx: index);
- final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
- // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
- final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
- pageStartInstanceFn(context:context);
- }else {
- if(isFirstInitSwitch??false){
- final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
- // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
- final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
- pageStartInstanceFn(context:context);
- }
- }
- }
- }
|