|
@@ -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;
|
|
|
- }else {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
@override
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
final vm = ref.read(communityVmProvider.notifier);
|
|
|
- BuildContext contextPage = context;
|
|
|
-
|
|
|
- final _tabsRouterKey = GlobalKey<AutoTabsRouterState>();
|
|
|
+ final state = ref.watch(communityVmProvider);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ 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.backgroundWhite,
|
|
|
+ backgroundColor: context.appColors.whiteBG,
|
|
|
+ ): MyAppBar.searchAppBar(
|
|
|
+ context,
|
|
|
+ actions: [
|
|
|
+ IconButton(
|
|
|
+ icon: const Icon(Icons.search),
|
|
|
+ onPressed: () {
|
|
|
+
|
|
|
+ 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);
|
|
|
- },
|
|
|
- ),
|
|
|
- ),
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- ];
|
|
|
- },
|
|
|
- body: NotificationListener<ScrollNotification>(
|
|
|
- onNotification: (ScrollNotification notification) {
|
|
|
-
|
|
|
-
|
|
|
- return false;
|
|
|
+ backgroundColor: context.appColors.backgroundDefault,
|
|
|
+ body: AutoTabsRouter.pageView(
|
|
|
+ key: tabsRouterKey,
|
|
|
+ routes: const [
|
|
|
+ NewsPageRoute(),
|
|
|
+ FollowingPageRoute(),
|
|
|
+ ForyouPageRoute(),
|
|
|
+ ForsalePageRoute(),
|
|
|
+ ForrentPageRoute(),
|
|
|
+ ],
|
|
|
+
|
|
|
+ builder: (context, child, pageController) {
|
|
|
+ final tabsRouter = AutoTabsRouter.of(context);
|
|
|
+
|
|
|
+ return NestedScrollView(
|
|
|
+ headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
|
|
+ return [
|
|
|
+
|
|
|
+ SliverToBoxAdapter(
|
|
|
+ child: _buildTopSection(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);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
- vm.setTabsRouterAndPageController(tabsRouter, pageController);
|
|
|
- });
|
|
|
-
|
|
|
- return Column(
|
|
|
- mainAxisSize: MainAxisSize.max,
|
|
|
- children: [
|
|
|
-
|
|
|
- _buildTabsSection(contextPage, ref, tabsRouter),
|
|
|
-
|
|
|
- _buildPostSection(context, ref, vm),
|
|
|
- Expanded(
|
|
|
- child: child,
|
|
|
- ),
|
|
|
- ],
|
|
|
- );
|
|
|
- },
|
|
|
- ),
|
|
|
- ),
|
|
|
- )
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _buildTopSection(BuildContext context, WidgetRef ref, vm) {
|
|
|
+
|
|
|
+ Widget _buildTopSection(BuildContext context, WidgetRef ref, vm, state) {
|
|
|
final topSectionsData = vm.topSectionsData;
|
|
|
+
|
|
|
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(
|
|
|
-
|
|
|
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){
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ 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){
|
|
|
+
|
|
|
+ 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((){
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
+
|