glglove 3 months ago
parent
commit
4c20397075

+ 19 - 3
packages/cpt_property/lib/modules/property/page/property_page.dart

@@ -15,6 +15,7 @@ import 'package:widgets/my_appbar.dart';
 import '../../../router/page/property_page_router.dart';
 import '../vm/property_vm.dart';
 
+final tabsRouterKey = GlobalKey<AutoTabsRouterState>();
 @RoutePage()
 class PropertyPage extends HookConsumerWidget {
   const PropertyPage({Key? key}) : super(key: key);
@@ -95,26 +96,41 @@ class PropertyPage extends HookConsumerWidget {
   Widget build(BuildContext context, WidgetRef ref) {
     final _vm = ref.read(propertyVmProvider.notifier);
     final state = ref.watch(propertyVmProvider);
-
     final isCollection = useState<bool>(false);
+
+    useEffect((){
+      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);
+      };
+    },[]);
     return Scaffold(
         appBar: MyAppBar.appBar(
           context,
           "Property",
           backgroundColor: context.appColors.backgroundWhite,
           actions: [
-             MyAssetImage(
+             state.currentPageViewIdx == 1? MyAssetImage(
               isCollection.value? Assets.propertyCollectionActive: Assets.propertyCollection,
               width: 22.5,
               height: 21,
             ).onTap((){
                isCollection.value = !isCollection.value;
               _vm.handlerCollectionFilter(context,isCollection.value);
-            }),
+            }):Container(),
             const SizedBox(width: 20),
           ],
         ),
         body: AutoTabsRouter.pageView(
+          key: tabsRouterKey,
           routes: const [
             PropertyIoanPageRoute(),
             PropertyNewsPageRoute(),

+ 4 - 4
packages/cpt_property/lib/modules/property/page/property_page_state.dart

@@ -7,11 +7,11 @@ import '../../sale/page/property_sale_page.dart';
 
 class PropertyVmState {
   List<Map<String, dynamic>>? topSectionsData;
-  int? curIdx;
+  int? currentPageViewIdx;
 
   PropertyVmState({
     List<Map<String, dynamic>>? topSectionsData,
-    this.curIdx = 0,
+    this.currentPageViewIdx = 0,
   }) : topSectionsData = topSectionsData?? [
     {
       "title": "Ioan",
@@ -41,11 +41,11 @@ class PropertyVmState {
 
   PropertyVmState copyWith({
     List<Map<String, dynamic>>? topSectionsData,
-    int? curIdx = 0,
+    int? currentPageViewIdx = 0,
   }) {
     return PropertyVmState(
       topSectionsData: topSectionsData ?? this.topSectionsData,
-      curIdx: curIdx ?? 0,
+      currentPageViewIdx: currentPageViewIdx ?? 0,
     );
   }
 }

+ 5 - 16
packages/cpt_property/lib/modules/property/vm/property_vm.dart

@@ -10,6 +10,7 @@ import '../../ioan/property_ioan_page.dart';
 import '../../news/page/property_news_page.dart';
 import '../../rent/page/property_rent_page.dart';
 import '../../sale/page/property_sale_page.dart';
+import '../page/property_page.dart';
 import '../page/property_page_state.dart';
 
 part 'property_vm.g.dart';
@@ -38,22 +39,10 @@ class PropertyVm extends _$PropertyVm {
     return state;
   }
 
-  // 页面切换
-  switchPage(int index,BuildContext? context, [bool? isFirstInitSwitch] ){
-    if(state.curIdx != index){
-      state = state.copyWith(curIdx: index);
-      final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
-      // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
-      final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
-      pageStartInstanceFn(context:context);
-    }else {
-      if(isFirstInitSwitch??false){
-        final List<Map<String, dynamic>>? topSectionsData = state.topSectionsData;
-        // Log.d("当前页面${topSectionsData?[index]['pageStartInstanceFn']}");
-        final pageStartInstanceFn = topSectionsData?[index]['pageStartInstanceFn'] as Function({BuildContext? context});
-        pageStartInstanceFn(context:context);
-      }
-    }
+  tabsRouterChange(){
+    // 设置当前导航栏的 图标 等状态
+    Log.d("----tabsRouterChange---${tabsRouterKey.currentState?.controller?.activeIndex}-");
+    state = state.copyWith(currentPageViewIdx: tabsRouterKey.currentState?.controller?.activeIndex ?? 0);
   }
 
   // 点击了导航的 搜索 进行筛选