瀏覽代碼

add scroll indicator

Destiny 8 月之前
父節點
當前提交
962b7f4eaa
共有 2 個文件被更改,包括 77 次插入42 次删除
  1. 1 0
      lib/module/store/discount/discount_view.dart
  2. 76 42
      lib/module/store/discount/func_page_view.dart

+ 1 - 0
lib/module/store/discount/discount_view.dart

@@ -199,6 +199,7 @@ class _FeaturesPreview extends StatelessWidget {
           icon: Assets.images.iconStorePremium.image(),
         ),
       ],
+      showIndicator: true,
     );
   }
 }

+ 76 - 42
lib/module/store/discount/func_page_view.dart

@@ -9,6 +9,7 @@ class InfinitePreviewPageView extends StatefulWidget {
   final double height;
   final Duration autoPlayDuration;
   final bool autoPlay;
+  final bool showIndicator;
 
   const InfinitePreviewPageView({
     super.key,
@@ -16,6 +17,7 @@ class InfinitePreviewPageView extends StatefulWidget {
     this.height = 98,
     this.autoPlayDuration = const Duration(seconds: 3),
     this.autoPlay = true,
+    this.showIndicator = true,
   });
 
   @override
@@ -80,54 +82,86 @@ class _InfinitePreviewPageViewState extends State<InfinitePreviewPageView> {
     super.dispose();
   }
 
+  // 构建页面指示器
+  Widget _buildPageIndicator() {
+    return Row(
+      mainAxisAlignment: MainAxisAlignment.center,
+      children: List.generate(
+        widget.items.length,
+            (index) {
+          bool isActive = index == _actualPage;
+          return Container(
+            margin: EdgeInsets.symmetric(horizontal: 4.w),
+            height: 6.w,
+            width: 6.w,
+            decoration: BoxDecoration(
+              color: isActive ? Colors.white : Colors.white.withOpacity(0.22),
+              borderRadius: BorderRadius.circular(6.r),
+            ),
+          );
+        },
+      ),
+    );
+  }
+
   @override
   Widget build(BuildContext context) {
     if (widget.items.isEmpty) return const SizedBox();
 
-    return SizedBox(
-      height: widget.height,
-      child: PageView.builder(
-        controller: _pageController,
-        itemBuilder: (context, index) {
-          final itemIndex = index % widget.items.length;
-
-          // 如果还没初始化完成,不应用缩放效果
-          if (!_isInitialized) {
-            return Padding(
-              padding: const EdgeInsets.symmetric(horizontal: 8),
-              child: Container(
-                decoration: BoxDecoration(
-                  color: const Color(0xFF1E1E1E),
-                  borderRadius: BorderRadius.circular(16),
-                ),
-                child: widget.items[itemIndex],
-              ),
-            );
-          }
-
-          // 计算缩放和透明度
-          double diffScale = (_currentPage - index).abs();
-          double scale = 1 - (diffScale * 0.1).clamp(0.0, 0.3);
-          double opacity = 1 - (diffScale * 0.3).clamp(0.0, 0.5);
-
-          return Transform.scale(
-            scale: scale,
-            child: Opacity(
-              opacity: opacity,
-              child: Padding(
-                padding: const EdgeInsets.symmetric(horizontal: 0),
-                child: Container(
-                  decoration: BoxDecoration(
-                    color: const Color(0xFF1E1E1E),
-                    borderRadius: BorderRadius.circular(23.r),
+    return Column(
+      children: [
+        SizedBox(
+          height: widget.height,
+          child: PageView.builder(
+            controller: _pageController,
+            itemBuilder: (context, index) {
+              final itemIndex = index % widget.items.length;
+
+              // 如果还没初始化完成,不应用缩放效果
+              if (!_isInitialized) {
+                return Padding(
+                  padding: const EdgeInsets.symmetric(horizontal: 8),
+                  child: Container(
+                    decoration: BoxDecoration(
+                      color: const Color(0xFF1E1E1E),
+                      borderRadius: BorderRadius.circular(16),
+                    ),
+                    child: widget.items[itemIndex],
+                  ),
+                );
+              }
+
+              // 计算缩放和透明度
+              double diffScale = (_currentPage - index).abs();
+              double scale = 1 - (diffScale * 0.1).clamp(0.0, 0.3);
+              double opacity = 1 - (diffScale * 0.3).clamp(0.0, 0.5);
+
+              return Transform.scale(
+                scale: scale,
+                child: Opacity(
+                  opacity: opacity,
+                  child: Padding(
+                    padding: const EdgeInsets.symmetric(horizontal: 0),
+                    child: Container(
+                      decoration: BoxDecoration(
+                        color: const Color(0xFF1E1E1E),
+                        borderRadius: BorderRadius.circular(23.r),
+                      ),
+                      child: widget.items[itemIndex],
+                    ),
                   ),
-                  child: widget.items[itemIndex],
                 ),
-              ),
-            ),
-          );
-        },
-      ),
+              );
+            },
+          ),
+        ),
+        // 添加页面指示器,仅当showIndicator为true时显示
+        if (widget.showIndicator)
+          Padding(
+            padding: EdgeInsets.only(top: 10.h),
+            child: _buildPageIndicator(),
+          ),
+      ],
     );
   }
 }