|
@@ -21,6 +21,9 @@ import 'newsfeed_tabs.dart';
|
|
|
import 'community_vm.dart';
|
|
|
import 'customSilverHeaderTabs.dart';
|
|
|
|
|
|
+final tabsRouterKey = GlobalKey<AutoTabsRouterState>();
|
|
|
+
|
|
|
+
|
|
|
@RoutePage()
|
|
|
class CommunityPage extends HookConsumerWidget {
|
|
|
const CommunityPage({Key? key}) : super(key: key);
|
|
@@ -34,132 +37,107 @@ class CommunityPage extends HookConsumerWidget {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- bool _isPreventScroll(ScrollNotification notification, WidgetRef ref){
|
|
|
- // 检查当前页面是否是可见的
|
|
|
- bool isDownOrUp = notification.metrics.axis == Axis.vertical;
|
|
|
- if (notification is UserScrollNotification) {
|
|
|
- // 检查滚动方向
|
|
|
- switch (notification.direction) {
|
|
|
- case ScrollDirection.forward:
|
|
|
- print('Scrolling down');
|
|
|
- break;
|
|
|
- case ScrollDirection.reverse:
|
|
|
- print('Scrolling up');
|
|
|
- break;
|
|
|
- case ScrollDirection.idle:
|
|
|
- print('Scrolling stopped');
|
|
|
- break;
|
|
|
- }
|
|
|
- } else if (notification is ScrollUpdateNotification) {
|
|
|
- // 检查滚动位置变化
|
|
|
- double currentScrollPosition = notification.metrics.pixels;
|
|
|
- double maxScrollExtent = notification.metrics.maxScrollExtent;
|
|
|
-
|
|
|
- // 判断是否满足某个条件
|
|
|
- if (currentScrollPosition > 0 && currentScrollPosition < maxScrollExtent) {
|
|
|
- print('Current scroll position: $currentScrollPosition');
|
|
|
- // 在这里添加你的条件判断逻辑
|
|
|
- }
|
|
|
-
|
|
|
- // 只有当上下滚动时才拦截通知
|
|
|
- if (isDownOrUp) {
|
|
|
- final vm = ref.read(communityVmProvider.notifier);
|
|
|
- final currentTabRouter = vm.state!.tabsRouter;
|
|
|
- if(currentTabRouter!.activeIndex == 0){
|
|
|
- return false; // false 不拦截
|
|
|
- }else {
|
|
|
- return true; // true 拦截
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
@override
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
final vm = ref.read(communityVmProvider.notifier);
|
|
|
- BuildContext contextPage = context;
|
|
|
- // 创建 GlobalKey
|
|
|
- final _tabsRouterKey = GlobalKey<AutoTabsRouterState>();
|
|
|
+ final state = ref.watch(communityVmProvider);
|
|
|
|
|
|
- // useEffect((){
|
|
|
- // Log.d("CommunityPage initState");
|
|
|
- // return () {
|
|
|
- // Log.d("CommunityPage dispose");
|
|
|
- // };
|
|
|
- // },[]);
|
|
|
+ useEffect((){
|
|
|
+ Log.d("CommunityPage initState");
|
|
|
+ // 延迟监听
|
|
|
+ WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
|
|
+ if(tabsRouterKey.currentState?.controller != null){
|
|
|
+ tabsRouterKey.currentState?.controller?.addListener((){
|
|
|
+ vm.tabsRouterChange();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return (){
|
|
|
+ Log.d("CommunityPage dispose");
|
|
|
+ tabsRouterKey.currentState?.controller?.removeListener(vm.tabsRouterChange);
|
|
|
+ };
|
|
|
+ },[tabsRouterKey.currentState?.controller]);
|
|
|
|
|
|
return Scaffold(
|
|
|
- appBar: MyAppBar.appBar(
|
|
|
+ appBar: state.currentCategoryIdx == 0 ? MyAppBar.appBar(
|
|
|
context,
|
|
|
"Community",
|
|
|
backgroundColor: context.appColors.whiteBG,
|
|
|
+ ): MyAppBar.searchAppBar(
|
|
|
+ context,
|
|
|
+ actions: [
|
|
|
+ IconButton(
|
|
|
+ icon: const Icon(Icons.search),
|
|
|
+ onPressed: () {
|
|
|
+ // do something
|
|
|
+ vm.handlerChooseGarageCategory(context);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ backgroundColor: context.appColors.whiteBG,
|
|
|
),
|
|
|
- backgroundColor: context.appColors.backgroundDefault,
|
|
|
- body: NestedScrollView(
|
|
|
- headerSliverBuilder: (context, innerBoxIsScrolled) {
|
|
|
- return [
|
|
|
- SliverToBoxAdapter(
|
|
|
- child: Consumer(
|
|
|
- builder: (context, ref, _) {
|
|
|
- return _buildTopSection(context, ref, vm);
|
|
|
- },
|
|
|
- ),
|
|
|
- ),
|
|
|
- // SliverPersistentHeader(
|
|
|
- // pinned: true, // 吸顶
|
|
|
- // delegate: CustomSliverPersistentHeaderDelegate(
|
|
|
- // child: _buildTabsSection(contextPage, ref),
|
|
|
- // ),
|
|
|
- // ),
|
|
|
- ];
|
|
|
- },
|
|
|
- body: NotificationListener<ScrollNotification>(
|
|
|
- onNotification: (ScrollNotification notification) {
|
|
|
- // 是否拦截滚动 false 表示不拦截通知
|
|
|
- // return _isPreventScroll(notification, ref);
|
|
|
- return false;
|
|
|
+ backgroundColor: context.appColors.backgroundDefault,
|
|
|
+ body: AutoTabsRouter.pageView(
|
|
|
+ key: tabsRouterKey,
|
|
|
+ routes: const [
|
|
|
+ NewsPageRoute(),
|
|
|
+ FollowingPageRoute(),
|
|
|
+ ForyouPageRoute(),
|
|
|
+ ForsalePageRoute(),
|
|
|
+ ForrentPageRoute(),
|
|
|
+ ],
|
|
|
+ // physics: const NeverScrollableScrollPhysics(), // 禁止滚动
|
|
|
+ builder: (context, child, pageController) {
|
|
|
+ final tabsRouter = AutoTabsRouter.of(context);
|
|
|
+
|
|
|
+ return NestedScrollView(
|
|
|
+ headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
|
|
+ return [
|
|
|
+ // top 组件,转换为 Sliver 组件
|
|
|
+ SliverToBoxAdapter(
|
|
|
+ child: _buildTopSection(context, ref, vm, state),
|
|
|
+ ),
|
|
|
+ // tab 组件,使用 SliverPersistentHeader 实现吸顶
|
|
|
+ // SliverPersistentHeader(
|
|
|
+ // pinned: true,
|
|
|
+ // delegate: CustomSliverPersistentHeaderDelegate(
|
|
|
+ // child: _buildTabsSection(context, ref, tabsRouter, vm, state),
|
|
|
+ // ),
|
|
|
+ // ),
|
|
|
+ // SliverToBoxAdapter(
|
|
|
+ // child: _buildPostSection(context, ref, vm, state),
|
|
|
+ // ),
|
|
|
+ ];
|
|
|
},
|
|
|
- child: AutoTabsRouter.pageView(
|
|
|
- key: _tabsRouterKey,
|
|
|
- routes: const [
|
|
|
- NewsPageRoute(),
|
|
|
- FollowingPageRoute(),
|
|
|
- ForyouPageRoute()
|
|
|
+ body: Column(
|
|
|
+ mainAxisSize: MainAxisSize.max,
|
|
|
+ children: [
|
|
|
+ _buildTabsSection(context, ref, tabsRouter, vm, state),
|
|
|
+ _buildPostSection(context, ref, vm, state),
|
|
|
+ Expanded(
|
|
|
+ child: child
|
|
|
+ ),
|
|
|
],
|
|
|
- builder: (context, child, pageController) {
|
|
|
- final tabsRouter = AutoTabsRouter.of(context);
|
|
|
- // Log.d("autotabsrouter build ${tabsRouter.activeIndex}");
|
|
|
- // Log.d("communityVmProvider.notifier state.tabsRouter.tabsRouter: ${ref.read(communityVmProvider.notifier).state.tabsRouter}");
|
|
|
- // ref.read(communityVmProvider.notifier).state.tabsRouter = tabsRouter;
|
|
|
- // ref.read(communityVmProvider.notifier).state.pageController = pageController;
|
|
|
- // Log.d("communityVmProvider.notifier state.tabsRouter.tabsRouter.activeIndex: ${ref.read(communityVmProvider.notifier).state.tabsRouter.activeIndex}");
|
|
|
- WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
- vm.setTabsRouterAndPageController(tabsRouter, pageController);
|
|
|
- });
|
|
|
-
|
|
|
- return Column(
|
|
|
- mainAxisSize: MainAxisSize.max,
|
|
|
- children: [
|
|
|
- // tab 组件
|
|
|
- _buildTabsSection(contextPage, ref, tabsRouter),
|
|
|
- // post 组件
|
|
|
- _buildPostSection(context, ref, vm),
|
|
|
- Expanded(
|
|
|
- child: child,
|
|
|
- ),
|
|
|
- ],
|
|
|
- );
|
|
|
- },
|
|
|
- ),
|
|
|
- ),
|
|
|
- )
|
|
|
+ ), // post 组件和其他内容
|
|
|
+ );
|
|
|
+ },
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _buildTopSection(BuildContext context, WidgetRef ref, vm) {
|
|
|
+
|
|
|
+ Widget _buildTopSection(BuildContext context, WidgetRef ref, vm, state) {
|
|
|
final topSectionsData = vm.topSectionsData;
|
|
|
+ // final currentPageIdx = tabsRouterKey.currentState?.controller?.activeIndex ?? 0;
|
|
|
int curTagIdx = 0;
|
|
|
+ int currentPageIdx = state.currentPageViewIdx;
|
|
|
+ int newsfeedTabCount = state.newsFeedTabsList.length;
|
|
|
+ if(currentPageIdx >= newsfeedTabCount){
|
|
|
+ curTagIdx = 1;
|
|
|
+ }else {
|
|
|
+ curTagIdx = 0;
|
|
|
+ }
|
|
|
return Container(
|
|
|
color: context.appColors.whiteBG,
|
|
|
padding: const EdgeInsets.only(top: 23, bottom: 30),
|
|
@@ -176,7 +154,6 @@ class CommunityPage extends HookConsumerWidget {
|
|
|
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 == curTagIdx ? [
|
|
|
BoxShadow(
|
|
@@ -184,14 +161,14 @@ class CommunityPage extends HookConsumerWidget {
|
|
|
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);
|
|
|
+ vm.handlerSwitchNewsfeedOrGaragesale(index, context, null);
|
|
|
},
|
|
|
type: ClickType.throttle,
|
|
|
),
|
|
@@ -212,24 +189,50 @@ class CommunityPage extends HookConsumerWidget {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _buildTabsSection(BuildContext context, WidgetRef ref, tabsRouter){
|
|
|
- final vm = ref.read(communityVmProvider.notifier);
|
|
|
- final tabsList = ref.watch(communityVmProvider.select((state) => state.tabsList));
|
|
|
+ Widget _buildTabsSection(BuildContext context, WidgetRef ref, tabsRouter, vm, state){
|
|
|
+ int currentPageIndex = tabsRouter!.activeIndex ?? 0;
|
|
|
+ int newsfeedTabCount = state.newsFeedTabsList.length;
|
|
|
+
|
|
|
+ List<String> tabsList;
|
|
|
+ if(currentPageIndex < newsfeedTabCount){
|
|
|
+ // news feed
|
|
|
+ tabsList = state.newsFeedTabsList ?? [];
|
|
|
+ }else {
|
|
|
+ tabsList = state.garageSaleTabsList ?? [];
|
|
|
+ }
|
|
|
return Container(
|
|
|
width: double.infinity,
|
|
|
- padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
|
|
|
+ padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 12),
|
|
|
+ color: ColorUtils.string2Color('#F2F3F6'),
|
|
|
child: NewsfeedTabs(
|
|
|
key: UniqueKey(),
|
|
|
- tabsList: tabsList!,
|
|
|
+ tabsList: tabsList,
|
|
|
tabsRouter: tabsRouter,
|
|
|
- onClickAction:(activeTabIdx){
|
|
|
- vm.handlerChangeTab(activeTabIdx, tabsRouter);
|
|
|
+ onClickAction:(Map<String, dynamic>? params){
|
|
|
+ if (params != null) {
|
|
|
+ // 解构 params
|
|
|
+ final int? currentCatgoryIdx = params['currentCatgoryIdx'] as int?;
|
|
|
+ final int? tabIdx = params['tabIdx'] as int?;
|
|
|
+ vm.handlerChangeTab(tabIdx, tabsRouter, currentCatgoryIdx);
|
|
|
+ }
|
|
|
}
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
|
|
|
+ Widget _buildPostSection(BuildContext context, WidgetRef ref, vm, state){
|
|
|
+ int currentPageIndex = state.currentPageViewIdx;
|
|
|
+ int newsfeedTabCount = state.newsFeedTabsList.length;
|
|
|
+ if(currentPageIndex < newsfeedTabCount){
|
|
|
+ // news feed
|
|
|
+ return _buildNewsFeedPost(context, ref, vm, state);
|
|
|
+ }else {
|
|
|
+ return _buildGarageSalePost(context, ref, vm, state);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _buildNewsFeedPost(BuildContext context, WidgetRef ref, vm, state){
|
|
|
return Container(
|
|
|
height: 65.5,
|
|
|
width: double.infinity,
|
|
@@ -238,31 +241,63 @@ class CommunityPage extends HookConsumerWidget {
|
|
|
child: Row(
|
|
|
children: [
|
|
|
const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
|
|
|
- Expanded(
|
|
|
- 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,
|
|
|
- ),
|
|
|
+ Expanded(
|
|
|
+ child: MyTextView(
|
|
|
+ "What’s on your mind?",
|
|
|
+ textColor: context.appColors.textBlack,
|
|
|
+ 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);
|
|
|
-
|
|
|
- MyPostsPage.startInstance();
|
|
|
+ vm.handlerGotoNewsfeedPost(context);
|
|
|
}),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ Widget _buildGarageSalePost(BuildContext context, WidgetRef ref, vm, state){
|
|
|
+ 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: MyTextView(
|
|
|
+ "Sell Item",
|
|
|
+ textColor: context.appColors.textBlack,
|
|
|
+ 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.handlerGotoGaragePost(context);
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
+
|