Procházet zdrojové kódy

update community module

gaol před 1 týdnem
rodič
revize
846c9195a8

+ 43 - 23
packages/cpt_community/lib/modules/community/community_page.dart

@@ -10,6 +10,7 @@ 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 'community_vm.dart';
@@ -28,10 +29,11 @@ class CommunityPage extends HookConsumerWidget {
     }
 
 
-     Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm) {
+     Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm, tabsRouter) {
         final topSectionsData = _vm.topSectionsData;
+        final currentTabIdx = tabsRouter.activeIndex;
         // 监听 curIdx 的变化
-        final curIdx = ref.watch(communityVmProvider.select((value) => value.curIdx));
+        // final curIdx = ref.watch(communityVmProvider.select((value) => value.curIdx));
         return Container(
           color: Colors.white,
           padding: const EdgeInsets.only(top: 30, bottom: 30),
@@ -45,15 +47,30 @@ class CommunityPage extends HookConsumerWidget {
                   flex: 1,
                   child: Column(
                     children: [
-                      MyAssetImage(
-                        item['icon'],
+                      Container(
                         width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
                         height: 70,
-                      ).onTap(
-                            () {
-                          _vm.switchPage(index, context);
-                        },
-                        type: ClickType.throttle,
+                        decoration: BoxDecoration(
+                          // color: currentTabIdx == index ? ColorUtils.string2Color('#E6F2FF') : Colors.white,
+                          shape: BoxShape.circle, // 设置为圆形
+                          boxShadow: tabsRouter.activeIndex == index ? [
+                            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(() {
+                            tabsRouter.setActiveIndex(index);
+                          },
+                          type: ClickType.throttle,
+                        ),
                       ),
                       SizedBox.fromSize(size: const Size(0, 9)),
                       Text(
@@ -62,7 +79,7 @@ class CommunityPage extends HookConsumerWidget {
                         overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
                         style: TextStyle(
                             fontSize: 15.0,
-                            color: curIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
+                            color: currentTabIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
                             fontWeight: FontWeight.w500
                         ), // 设置字体大小
                       ),
@@ -85,20 +102,23 @@ class CommunityPage extends HookConsumerWidget {
               backgroundColor: context.appColors.whiteBG,
             ),
             backgroundColor: context.appColors.backgroundDefault,
-            body: Row(
-              children: [
-                Expanded(
-                  child: Column(
-                    children: [
-                      _buildTopSection(context, ref, vm),
-                      const Expanded(
-                        child: AutoRouter(),
-                      )
-                    ],
+          body: AutoTabsRouter.pageView(
+            routes: const [
+              NewsfeedPageRoute(),
+              GaragesalePageRoute(),
+            ],
+            builder: (context, child, pageController) {
+              final tabsRouter = AutoTabsRouter.of(context);
+              return Column(
+                children: [
+                  _buildTopSection(context, ref, vm, tabsRouter),
+                  Expanded(
+                    child: child,
                   ),
-                )
-              ],
-            )
+                ],
+              );
+            },
+          ),
         );
     }
 }

+ 104 - 0
packages/cpt_community/lib/modules/community/community_page1.dart

@@ -0,0 +1,104 @@
+
+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/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 '../../router/page/community_page_router.dart';
+import 'community_vm.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());
+    }
+  }
+
+
+  Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm) {
+    final topSectionsData = _vm.topSectionsData;
+    // 监听 curIdx 的变化
+    final curIdx = ref.watch(communityVmProvider.select((value) => value.curIdx));
+    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: [
+                  MyAssetImage(
+                    item['icon'],
+                    width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
+                    height: 70,
+                  ).onTap(
+                        () {
+                      _vm.switchPage(index, context);
+                    },
+                    type: ClickType.throttle,
+                  ),
+                  SizedBox.fromSize(size: const Size(0, 9)),
+                  Text(
+                    item['title'],
+                    maxLines: 1, // 设置最大行数为2
+                    overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
+                    style: TextStyle(
+                        fontSize: 15.0,
+                        color: curIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
+                        fontWeight: FontWeight.w500
+                    ), // 设置字体大小
+                  ),
+                ],
+              ),
+            ).marginOnly(left: 18, right: 18, top: 10, bottom: 10);
+          }),
+        ),
+      ),
+    );
+  }
+
+  @override
+  Widget build(BuildContext context, WidgetRef ref) {
+    final vm = ref.watch(communityVmProvider.notifier);
+    return Scaffold(
+        appBar: MyAppBar.appBar(
+          context,
+          "Community",
+          backgroundColor: context.appColors.whiteBG,
+        ),
+        backgroundColor: context.appColors.backgroundDefault,
+        body: Row(
+          children: [
+            Expanded(
+              child: Column(
+                children: [
+                  _buildTopSection(context, ref, vm),
+                  const Expanded(
+                    child: AutoRouter(),
+                  )
+                ],
+              ),
+            )
+          ],
+        )
+    );
+  }
+}

+ 0 - 5
packages/cpt_community/lib/modules/community/community_vm.dart

@@ -25,11 +25,6 @@ class CommunityVm extends _$CommunityVm {
     final state = initState();
     Log.d("--------------------------build---------------------");
 
-    // 初始时导航到子路由
-    WidgetsBinding.instance.addPostFrameCallback((_) {
-      switchPage(state.curIdx ?? 0, null, true);
-    });
-
     return state;
   }
 

+ 16 - 13
packages/cpt_community/lib/modules/newsfeed/newsfeed_page.dart

@@ -152,20 +152,23 @@ class NewsfeedPage extends HookConsumerWidget {
 
             _buildPostSection(context, ref, vm),
 
+            // Expanded(
+            //   child: EasyRefresh(
+            //     // 上拉加载
+            //     onLoad: () async{
+            //       Log.d("----onLoad");
+            //       vm.onLoadData();
+            //     },
+            //     // 下拉刷新
+            //     onRefresh: () async{
+            //       Log.d("----onRefresh");
+            //       vm.refreshListData();
+            //     },
+            //     child: _buildNesFeedList(context, ref, vm),
+            //   ),
+            // )
             Expanded(
-              child: EasyRefresh(
-                // 上拉加载
-                onLoad: () async{
-                  Log.d("----onLoad");
-                  vm.onLoadData();
-                },
-                // 下拉刷新
-                onRefresh: () async{
-                  Log.d("----onRefresh");
-                  vm.refreshListData();
-                },
-                child: _buildNesFeedList(context, ref, vm),
-              ),
+              child: _buildNesFeedList(context, ref, vm),
             )
           ],
       ),

+ 42 - 23
packages/cpt_property/lib/modules/property/page/property_page.dart

@@ -27,10 +27,9 @@ class PropertyPage extends HookConsumerWidget {
   }
 
   // 顶部tab 切换
-  Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm) {
+  Widget _buildTopSection(BuildContext context, WidgetRef ref, _vm, tabsRouter) {
     final topSectionsData = _vm.topSectionsData;
-    // 监听 curIdx 的变化
-    final curIdx = ref.watch(propertyVmProvider.select((value) => value.curIdx));
+    final currentTabIdx = tabsRouter.activeIndex;
     return Container(
       color: Colors.white,
       child: Center(
@@ -43,15 +42,30 @@ class PropertyPage extends HookConsumerWidget {
               flex: 1,
               child: Column(
                 children: [
-                  MyAssetImage(
-                    item['icon'],
+                  Container(
                     width: MediaQuery.of(context).size.width / topSectionsData.length - 36,
                     height: 70,
-                  ).onTap(
-                    () {
-                      _vm.switchPage(index, context);
-                    },
-                    type: ClickType.throttle,
+                    decoration: BoxDecoration(
+                      // color: currentTabIdx == index ? ColorUtils.string2Color('#E6F2FF') : Colors.white,
+                      shape: BoxShape.circle, // 设置为圆形
+                      boxShadow: tabsRouter.activeIndex == index ? [
+                        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(() {
+                        tabsRouter.setActiveIndex(index);
+                      },
+                      type: ClickType.throttle,
+                    ),
                   ),
                   SizedBox.fromSize(size: const Size(0, 9)),
                   MyTextView(
@@ -59,7 +73,7 @@ class PropertyPage extends HookConsumerWidget {
                     maxLines: 1, // 设置最大行数为2
                     isTextEllipsis: true, // 超出部分用省略号表示
                     fontSize: 13,
-                    textColor: curIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
+                    textColor: currentTabIdx == index ? ColorUtils.string2Color('#4161D0'):Colors.black,
                     isFontMedium: true,
                   ),
                 ],
@@ -80,19 +94,24 @@ class PropertyPage extends HookConsumerWidget {
           "Property",
           backgroundColor: context.appColors.whiteBG,
         ),
-        body: Row(
-          children: [
-            Expanded(
-              child: Column(
-                children: [
-                  _buildTopSection(context, ref, _vm),
-                  const Expanded(
-                    child: AutoRouter(),
-                  )
-                ],
-              ),
-            )
+        body: AutoTabsRouter.pageView(
+          routes: const [
+            PropertyIoanPageRoute(),
+            PropertyNewsPageRoute(),
+            PropertySalePageRoute(),
+            PropertyRentPageRoute(),
           ],
+          builder: (context, child, pageController) {
+             final  tabsRouter = AutoTabsRouter.of(context);
+             return Column(
+               children: [
+                 _buildTopSection(context, ref, _vm, tabsRouter),
+                 Expanded(
+                   child: child,
+                 ),
+              ],
+             );
+          },
         )
     );
   }

+ 0 - 1
packages/cpt_property/lib/modules/property/vm/property_vm.dart

@@ -73,7 +73,6 @@ class PropertyVm extends _$PropertyVm {
 
     // 初始时导航到子路由
     WidgetsBinding.instance.addPostFrameCallback((_) {
-      switchPage(state.curIdx ?? 0, null, true);
     });
 
     return state;