12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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:router/path/router_path.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:auto_route/auto_route.dart';
- import '../newsfeed/newsfeed_post/newsfeed_post_page.dart';
- import 'community_state.dart';
- part 'community_vm.g.dart';
- @riverpod
- class CommunityVm extends _$CommunityVm {
- get topSectionsData => state.topSectionsData;
- CommunityVmState initState() {
- return CommunityVmState(
- activeTabIdx: 0,
- tabsList: ["News", "Following", "For You"],
- );
- }
- @override
- CommunityVmState build(){
- final state = initState();
- // 第一帧渲染完成
- WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
- });
- Log.d("--------------------------build---------------------");
- return state;
- }
- // 切换tab
- handlerChangeTab(int index) {
- // state.tabsRouter.setActiveIndex(activeTabIdx);
- // if(tabItem == "News"){
- // state = state.copyWith(activeTabIdx: 0);
- // }else if(tabItem == "Following"){
- // state = state.copyWith(activeTabIdx: 1);
- // }else if(tabItem == "For You"){
- // state = state.copyWith(activeTabIdx: 2);
- // }
- // state = state.copyWith(activeTabIdx: index);
- state.pageController?.jumpToPage(index);
- }
- // 设置当前的 tabsRouter 和 pageController
- Future setTabsRouterAndPageController(dynamic tabsRouter, dynamic pageController) async{
- // state = await state.copyWith(activeTabIdx: tabsRouter.activeIndex);
- Log.d("setTabsRouterAndPageController---: $tabsRouter");
- state = await state.copyWith(tabsRouter: tabsRouter, pageController: pageController,activeTabIdx: tabsRouter.activeIndex);
- // state = await state.copyWith(activeTabIdx: state.tabsRouter.activeIndex);
- }
- handlerChangeCommunityType(BuildContext context, int index){
- if(index == 1){
- // 跳转到 garage sale 页面
- AutoRouter.of(context).pushNamed(RouterPath.garageSale);
- }
- }
- // 点击发布的按钮 跳转到发布的页面
- void handlerGotoPost(context){
- // ComponentServiceManager().communityService.startCommunityPage();
- // AutoRouter.of(context).pushNamed(RouterPath.newsFeedPost);
- NewsfeedPostPage.startInstance();
- }
- }
|