import 'package:cpt_community/components/comments_dialog.dart'; import 'package:cpt_community/router/page/community_page_router.dart'; import 'package:cs_resources/generated/assets.dart'; import 'package:cs_resources/theme/app_colors_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:plugin_platform/engine/dialog/dialog_engine.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 'package:widgets/dialog/app_custom_dialog.dart'; import 'package:widgets/my_checkbox_group.dart'; import '../garage/garagesale_post/garagesale_post_page.dart'; import '../my_following/my_following_page.dart'; import '../my_posts/my_posts_page.dart'; import 'community_page.dart'; import 'community_state.dart'; import 'newsfeed_post/newsfeed_post_page.dart'; part 'community_vm.g.dart'; @riverpod class CommunityVm extends _$CommunityVm { get topSectionsData => state.topSectionsData; CommunityVmState initState() { return CommunityVmState( currentCategoryIdx: 0, currentPageViewIdx: 0, lastGarageTabIdx: 0, lastNewsfeedTabIdx: 0, newsFeedTabsList: [ "News", "Following", "For You", ], garageSaleTabsList: [ "For Sale", "For Rent", ], ); } @override CommunityVmState build(){ final state = initState(); // 第一帧渲染完成 WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { }); Log.d("--------------------------build---------------------"); return state; } tabsRouterChange(){ Log.d("----tabsRouterChange---${tabsRouterKey.currentState?.controller?.activeIndex}-"); state = state.copyWith(currentPageViewIdx: tabsRouterKey.currentState?.controller?.activeIndex ?? 0); } // 切换tab handlerChangeTab(int tabIndex, TabsRouter? tabsRouter, int? categoryIdx) { tabsRouter = (tabsRouter?? tabsRouterKey.currentState?.controller)!; categoryIdx = categoryIdx ?? state.currentCategoryIdx; if(categoryIdx == 0){ tabsRouter.setActiveIndex(tabIndex); }else { tabsRouter.setActiveIndex(state.newsFeedTabsList!.length + tabIndex); } } // 切换news feed和garage sale handlerSwitchNewsfeedOrGaragesale( int categoryIdx, BuildContext? context, TabsRouter? tabsRouter){ tabsRouter = (tabsRouter?? tabsRouterKey.currentState?.controller)!; categoryIdx = categoryIdx; if(categoryIdx == 0){ tabsRouter.setActiveIndex(state.lastNewsfeedTabIdx); }else if (categoryIdx == 1){ tabsRouter.setActiveIndex(state.newsFeedTabsList!.length + state.lastGarageTabIdx); } } // 设置当前的cat类型 setCurrentCategoryIdx(BuildContext? context, int categoryIdx, int? lastNewsfeedTabIdx, int? lastGarageTabIdx){ state = state.copyWith( currentCategoryIdx: categoryIdx, lastNewsfeedTabIdx: lastNewsfeedTabIdx?? state.lastNewsfeedTabIdx, lastGarageTabIdx: lastGarageTabIdx?? state.lastGarageTabIdx ); } // 判断当前pageview 页面正处于显示状态 Future isCurrentPageViewShowing(int pageViewIdx) async{ // 延迟获取结果 bool isShowing = await Future.delayed(const Duration(milliseconds: 500), (){ return state.currentPageViewIdx == pageViewIdx; }); return isShowing; } // 选择 garage sale 导航栏点击 选择分类 handlerChooseGarageCategory(BuildContext context) async { List> categoryList = [ { 'id': '1', 'label': 'Kids', }, { 'id': '2', 'label': 'Homeware', }, { 'id': '3', 'label': 'Fashion', }, { 'id': '4', 'label': 'Electronics', }, { 'id': '5', 'label': 'Sports', }, { 'id': '6', 'label': 'Furniture', }, { 'id': '7', 'label': 'Others', }, ]; await DialogEngine.show( tag: "chooseGarageSaleCategory", position: DialogPosition.center, widget: AppCustomDialog( message: '', dialogWidth: MediaQuery.of(context).size.width * 0.8, // contentBoxMaxHeight: 350, // contentBoxMinHeight: 300, confirmTxt: "Ok", messageBuilder: (BuildContext context){ return Container( color: context.appColors.textWhite, child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ MyCheckboxGroup( isSingleSelect: false, labelStyle: const TextStyle( fontSize: 16, fontWeight: FontWeight.w500, ), items: categoryList, onChanged: (List> selectedItems){ Log.d("----MyCheckboxGroup onChanged $selectedItems"); } ) ], ), ); }, isShowCancelBtn:false, confirmAction: (){ }, ) ); } // 点击了导航栏的 like btn handlerClickNavbarLikeBtn(BuildContext? context){ if(state.currentCategoryIdx ==0){ // ToastEngine.show("点击了 newsfeed like"); }else if(state.currentCategoryIdx == 1){ // ToastEngine.show("点击了 garagesale like"); } } // 点击了导航栏的 filter btn handlerClickNavbarFilterBtn(BuildContext? context,){ ToastEngine.show("点击 filter"); handlerChooseGarageCategory(context!); } // 点击发布的按钮 跳转到 newsfeed 发布的页面 void handlerGotoNewsfeedPost(context){ // AutoRouter.of(context).pushNamed(RouterPath.newsFeedPost); NewsfeedPostPage.startInstance(); // MyPostsPage.startInstance(); // MyFollowingPage.startInstance(); } // 点击发布的按钮 跳转到garagesale 发布的页面 void handlerGotoGaragePost(context){ GaragesalePostPage.startInstance(); } }