1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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 'community_state.dart';
- import '../garagesale/garagesale_page.dart';
- import '../newsfeed/newsfeed_page.dart';
- part 'community_vm.g.dart';
- @riverpod
- class CommunityVm extends _$CommunityVm {
- get topSectionsData => state.topSectionsData;
- CommunityVmState initState() {
- return CommunityVmState();
- }
- @override
- CommunityVmState 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);
- }
- }
- }
- }
|