12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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 './rewards_my_active/rewards_my_active_page.dart';
- import './rewards_my_expired/rewards_my_expired_page.dart';
- import './rewards_my_used/rewards_my_used_page.dart';
- part 'rewards_my_vm.g.dart';
- class RewardsMyVmState {
- List<Map<String, dynamic>>? topSectionsData;
- int? curIdx;
- RewardsMyVmState({
- List<Map<String, dynamic>>? topSectionsData,
- this.curIdx = 0,
- }) : topSectionsData = topSectionsData?? [
- {
- "title": "Active",
- "icon": Assets.propertyIoan,
- "pageStartInstanceFn": RewardsMyActivePage.startInstance,
- "page": const RewardsMyActivePage(),
- },
- {
- "title": "Expired",
- "icon": Assets.propertyNews,
- "pageStartInstanceFn": RewardsMyExpiredPage.startInstance,
- "page": const RewardsMyExpiredPage(),
- },
- {
- "title": "Used",
- "icon": Assets.propertySale,
- "pageStartInstanceFn": RewardsMyUsedPage.startInstance,
- "page": const RewardsMyUsedPage(),
- }
- ];
- RewardsMyVmState copyWith({
- List<Map<String, dynamic>>? topSectionsData,
- int? curIdx = 0,
- }) {
- return RewardsMyVmState(
- topSectionsData: topSectionsData ?? this.topSectionsData,
- curIdx: curIdx ?? 0,
- );
- }
- }
- @riverpod
- class RewardsMyVm extends _$RewardsMyVm {
- get topSectionsData => state.topSectionsData;
- RewardsMyVmState initState() {
- return RewardsMyVmState();
- }
- @override
- RewardsMyVmState build(){
- final state = initState();
- Log.d("--------------------------build---------------------");
- // 初始时导航到子路由
- WidgetsBinding.instance.addPostFrameCallback((_) {
- });
- 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);
- }
- }
- }
- }
|