12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import 'package:cpt_community/modules/my_posts/my_posts_vm.dart';
- import 'package:cpt_community/router/page/community_page_router.dart';
- import 'package:cs_resources/theme/app_colors_theme.dart';
- import 'package:flutter/material.dart';
- import 'package:auto_route/auto_route.dart';
- import 'package:hooks_riverpod/hooks_riverpod.dart';
- import 'package:router/ext/auto_router_extensions.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:widgets/my_appbar.dart';
- import '../my_posts/my_posts_forrent/my_posts_forrent_page.dart';
- import '../my_posts/my_posts_forsale/my_posts_forsale_page.dart';
- import '../my_posts/my_posts_newsfeed/my_posts_newsfeed_page.dart';
- import 'my_posts_tabs.dart';
- @RoutePage()
- class MyPostsPage extends HookConsumerWidget {
- const MyPostsPage({Key? key}) : super(key: key);
- //启动当前页面
- static void startInstance({BuildContext? context}) {
- if (context != null) {
- context.router.push(const MyPostsPageRoute());
- } else {
- appRouter.push(const MyPostsPageRoute());
- }
- }
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- BuildContext pageContext = context;
- final vm = ref.watch(myPostsVmProvider.notifier);
- final state = ref.watch(myPostsVmProvider);
- // // 创建 GlobalKey
- // final GlobalKey<AutoTabsRouterState> _tabsRouterKey = GlobalKey<AutoTabsRouterState>();
- return Scaffold(
- appBar: MyAppBar.appBar(
- context,
- "My Posts",
- backgroundColor: context.appColors.whiteBG,
- ),
- backgroundColor: context.appColors.backgroundDefault,
- body: Column(
- children: [
- Expanded(
- child: AutoTabsRouter.pageView(
- key: UniqueKey(),
- routes: const [
- MyPostsNewsfeedPageRoute(),
- MyPostsForSalePageRoute(),
- MyPostsForRentPageRoute()
- ],
- builder: (context, child, animation) {
- final tabsRouter = AutoTabsRouter.of(context);
- return Column(
- children: [
- _buildHeaderTabs(context, ref, state),
- Expanded(
- child: child,
- )
- ],
- );
- },
- )
- )
- ],
- ),
- );
- }
- Widget _buildHeaderTabs(BuildContext context, WidgetRef ref, state) {
- final vm = ref.read(myPostsVmProvider.notifier);
- return Container(
- color: Colors.blue,
- child: MyPostsTab(
- key: UniqueKey(),
- tabsList: state.tabsList,
- tabsRouter: null,
- onClickAction:(activeTabIdx){
- Log.d("点击的tab index: $activeTabIdx");
- vm.handlerChangeTab(context, activeTabIdx);
- },
- ),
- );
- }
- }
|