Browse Source

[feat]星座恋爱分析,支持传参直接切换到某个Tab

hezihao 8 tháng trước cách đây
mục cha
commit
e65e93db2a

+ 1 - 1
lib/module/intimacy_analyse/intimacy_analyse_controller.dart

@@ -75,7 +75,7 @@ class IntimacyAnalyseController extends BaseController
     pageController.animateToPage(
       index,
       duration: const Duration(milliseconds: 300),
-      curve: Curves.easeInToLinear,
+      curve: Curves.fastOutSlowIn,
     );
   }
 

+ 1 - 1
lib/module/intimacy_analyse/screenshot_reply/intimacy_analyse_screenshot_reply_controller.dart

@@ -38,7 +38,7 @@ class IntimacyAnalyseScreenshotReplyController extends BaseController
     pageController.animateToPage(
       index,
       duration: const Duration(milliseconds: 300),
-      curve: Curves.easeInToLinear,
+      curve: Curves.fastOutSlowIn,
     );
   }
 

+ 1 - 2
lib/module/zodiac_love_intimacy/enums/zodiac_love_intimacy_tab.dart

@@ -47,10 +47,9 @@ enum ZodiacLoveIntimacyTab {
   }
 
   /// 通过index,查找对应的Tab枚举实例
-  ZodiacLoveIntimacyTab fromIndex(int index) {
+  static ZodiacLoveIntimacyTab? fromIndex(int index) {
     return ZodiacLoveIntimacyTab.values.firstWhere(
       (element) => element.tabIndex == index,
-      orElse: () => today,
     );
   }
 }

+ 12 - 7
lib/module/zodiac_love_intimacy/zodiac_love_intimacy_controller.dart

@@ -88,25 +88,30 @@ class ZodiacLoveIntimacyController extends BaseController
     final arguments = Get.arguments as Map<String, dynamic>?;
 
     // 当前索引
-    int tabIndex = ZodiacLoveIntimacyTab.today.tabIndex;
+    ZodiacLoveIntimacyTab? tab;
     if (arguments?[AppPageArguments.index] == null) {
       AtmobLog.i(_tag, '没有传递 index 参数');
     } else {
       final int? index = arguments?[AppPageArguments.index] as int?;
       if (index != null) {
-        tabIndex = index;
-        AtmobLog.i(_tag, "index: $tabIndex");
+        tab = ZodiacLoveIntimacyTab.fromIndex(index);
+        if (tab != null) {
+          AtmobLog.i(_tag, "index: ${tab.tabIndex}");
+        }
       }
     }
 
+    // 默认选中第一个Tab
+    tab ??= ZodiacLoveIntimacyTab.today;
+
     // 创建PageController和TabController,并设置当前选中的index为初始索引
-    pageController = PageController(initialPage: tabIndex);
+    pageController = PageController(initialPage: tab.tabIndex);
     tabController = TabController(
-      initialIndex: tabIndex,
+      initialIndex: tab.tabIndex,
       length: tabBarList.length,
       vsync: this,
     );
-    currentTabIndex.value = tabIndex;
+    currentTabIndex.value = tab.tabIndex;
   }
 
   /// 返回
@@ -126,7 +131,7 @@ class ZodiacLoveIntimacyController extends BaseController
     pageController.animateToPage(
       index,
       duration: const Duration(milliseconds: 300),
-      curve: Curves.easeInToLinear,
+      curve: Curves.fastOutSlowIn,
     );
   }
 

+ 4 - 2
lib/module/zodiac_love_intimacy/zodiac_love_intimacy_page.dart

@@ -7,6 +7,7 @@ import 'package:keyboard/data/repository/account_repository.dart';
 import 'package:keyboard/module/zodiac_love_intimacy/tody/zodiac_love_today_view.dart';
 import 'package:keyboard/module/zodiac_love_intimacy/zodiac_love_intimacy_controller.dart';
 import 'package:keyboard/resource/colors.gen.dart';
+import 'package:keyboard/router/app_page_arguments.dart';
 import 'package:keyboard/utils/toast_util.dart';
 import 'package:lottie/lottie.dart';
 import 'package:nested_scroll_views/material.dart';
@@ -26,7 +27,7 @@ import 'future_week/zodiac_love_future_week_view.dart';
 class ZodiacLoveIntimacyPage extends BasePage<ZodiacLoveIntimacyController> {
   const ZodiacLoveIntimacyPage({super.key});
 
-  static start() {
+  static start({ZodiacLoveIntimacyTab tab = ZodiacLoveIntimacyTab.today}) {
     var accountRepository = getIt.get<AccountRepository>();
     // 如果用户未设置生日,则要求先设置生日,才能跳转
     if (accountRepository.userInfo.value?.birthday == null) {
@@ -34,7 +35,8 @@ class ZodiacLoveIntimacyPage extends BasePage<ZodiacLoveIntimacyController> {
       UserProfilePage.start();
       return;
     }
-    Get.toNamed(RoutePath.zodiacLoveIntimacy);
+    var args = {AppPageArguments.index: tab.tabIndex};
+    Get.toNamed(RoutePath.zodiacLoveIntimacy, arguments: args);
   }
 
   @override