123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- import 'package:cs_resources/generated/assets.dart';
- import 'package:flutter/material.dart';
- import 'package:auto_route/auto_route.dart';
- import 'package:flutter/rendering.dart';
- import 'package:flutter_hooks/flutter_hooks.dart';
- import 'package:hooks_riverpod/hooks_riverpod.dart';
- import 'package:router/ext/auto_router_extensions.dart';
- import 'package:shared/utils/color_utils.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:widgets/my_load_image.dart';
- import 'package:widgets/ext/ex_widget.dart';
- import 'package:widgets/my_text_view.dart';
- import 'package:widgets/my_appbar.dart';
- import 'package:cs_resources/theme/app_colors_theme.dart';
- import 'package:widgets/widget_export.dart';
- import '../../router/page/community_page_router.dart';
- import '../newsfeed/newsfeed_tabs.dart';
- import 'community_vm.dart';
- import 'customSilverHeaderTabs.dart';
- @RoutePage()
- class CommunityPage extends HookConsumerWidget {
- const CommunityPage({Key? key}) : super(key: key);
- //启动当前页面
- static void startInstance({BuildContext? context}) {
- if (context != null) {
- context.router.push(const CommunityPageRoute());
- } else {
- appRouter.push(const CommunityPageRoute());
- }
- }
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final vm = ref.read(communityVmProvider.notifier);
- final stateTabsRouter = ref.watch(communityVmProvider).tabsRouter;
- // final state = ref.watch(communityVmProvider);
- BuildContext contextPage = context;
- // useEffect((){
- // Log.d("CommunityPage initState");
- // return () {
- // Log.d("CommunityPage dispose");
- // };
- // },[]);
- return Scaffold(
- appBar: MyAppBar.appBar(
- context,
- "Community",
- backgroundColor: context.appColors.whiteBG,
- ),
- backgroundColor: context.appColors.backgroundDefault,
- body: NestedScrollView(
- headerSliverBuilder: (context, innerBoxIsScrolled) {
- return [
- SliverToBoxAdapter(
- child: Consumer(
- builder: (context, ref, _) {
- final tabsRouter = ref.watch(communityVmProvider).tabsRouter;
- // final vm = ref.read(communityVmProvider.notifier);
- if(tabsRouter != null){
- return _buildTopSection(context, ref, vm, tabsRouter);
- }else {
- return const SizedBox.shrink();
- }
- },
- ),
- ),
- // SliverPersistentHeader(
- // pinned: true, // 吸顶
- // delegate: CustomSliverPersistentHeaderDelegate(
- // child: _buildTabsSection(contextPage, ref),
- // ),
- // ),
- ];
- },
- body: AutoTabsRouter.pageView(
- routes: const [
- NewsPageRoute(),
- FollowingPageRoute(),
- ForyouPageRoute()
- ],
- builder: (context, child, pageController) {
- final tabsRouter = AutoTabsRouter.of(context);
- Log.d("autotabsRouter ---build ${tabsRouter.activeIndex}");
- // 将tabsRouter 放入 CommunityVmProvider 中
- // if(stateTabsRouter == null){
- // vm.setTabsRouterAndPageController(tabsRouter, pageController);
- // }else {
- //
- // }
- vm.setTabsRouterAndPageController(tabsRouter, pageController);
- return Column(
- children: [
- // Text("${vm.state.activeTabIdx}"),
- // _buildTabsSection(contextPage, ref, tabsRouter),
- // tabs 组件
- // Visibility(
- // visible: true,
- // child: _buildTabsSection(contextPage, ref, tabsRouter),
- // ),
- // post 组件
- // _buildPostSection(context, ref, vm),
- Expanded(
- child: child,
- ),
- ],
- );
- },
- ),
- )
- );
- }
- Widget _buildTopSection(BuildContext context, WidgetRef ref, vm, tabsRouter) {
- final topSectionsData = vm.topSectionsData;
- final currentTabIdx = tabsRouter.activeIndex;
- return Container(
- color: Colors.white,
- padding: const EdgeInsets.only(top: 30, bottom: 30),
- child: Center(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: List.generate(topSectionsData.length, (index) {
- final item = topSectionsData[index];
- return Flexible(
- flex: 1,
- child: Column(
- children: [
- Container(
- width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
- height: 70,
- decoration: BoxDecoration(
- // color: currentTabIdx == index ? ColorUtils.string2Color('#E6F2FF') : Colors.white,
- shape: BoxShape.circle, // 设置为圆形
- boxShadow: index == 0 ? [
- BoxShadow(
- color: context.appColors.tabLightBlueShadow, // 设置阴影颜色
- blurRadius: 5, // 设置模糊半径
- spreadRadius: 0.05, // 控制阴影扩散
- offset: const Offset(0, 4), // 设置阴影偏移量
- ), ] : [],// 未选中时无阴影,
- ),
- child: MyAssetImage(
- item['icon'],
- width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
- height: 70,
- ).onTap(() {
- vm.handlerChangeCommunityType(context,index);
- },
- type: ClickType.throttle,
- ),
- ),
- SizedBox.fromSize(size: const Size(0, 9)),
- MyTextView(
- item['title'],
- fontSize: 15,
- textColor: index ==0 ? ColorUtils.string2Color('#4161D0'):Colors.black,
- textAlign: TextAlign.center,
- isFontMedium: true,
- ),
- ],
- ),
- ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
- }),
- ),
- ),
- );
- }
- Widget _buildTabsSection(BuildContext context, WidgetRef ref, tabsRouter){
- final vm = ref.read(communityVmProvider.notifier);
- final tabsList = ref.watch(communityVmProvider.select((state) => state.tabsList));
- return Container(
- width: double.infinity,
- padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
- child: NewsfeedTabs(
- key: UniqueKey(),
- tabsList: tabsList!,
- onClickAction:(activeTabIdx){
- print('点击了tab ${activeTabIdx}');
- // vm.handlerChangeTab(activeTabIdx);
- // tabsRouter.setActiveIndex(activeTabIdx);
- }
- ),
- );
- }
- Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
- return Container(
- height: 65.5,
- width: double.infinity,
- padding: const EdgeInsets.only(left: 20, right: 20),
- color: Colors.white,
- child: Row(
- children: [
- const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
- Expanded(
- child: Row(
- children: [
- Expanded(
- child: Container(
- // height: 65.5,
- // color: Colors.blue,
- child: MyTextView(
- "What’s on your mind?",
- textColor: ColorUtils.string2Color('#000000'),
- fontSize: 15,
- marginLeft: 15,
- alignment: Alignment.centerLeft,
- textAlign: TextAlign.left,
- backgroundColor: ColorUtils.string2Color('#ffffff'),
- maxLines: 1,
- isFontMedium: true,
- ),
- ),
- ),
- const MyAssetImage(
- Assets.communityCamera,
- width: 21,
- height: 16.5,
- ),
- ],
- ).onTap((){
- vm.handlerGotoPost(context);
- }),
- ),
- ],
- ),
- );
- }
- }
|