From 2e47031e0ff2dd45129bdbd8d3037250ea69430c Mon Sep 17 00:00:00 2001 From: BreadKey <2breadkey@gmail.com> Date: Thu, 17 Jul 2025 14:20:21 +0900 Subject: [PATCH] feat: add activePreviousDot option to highlight previous dots - Add activePreviousDot parameter to DotsIndicator widget - When activePreviousDot is true, all dots with index <= position will use activeColor - Default value is false to maintain backward compatibility - Update comments to English for better internationalization --- .../xcshareddata/xcschemes/Runner.xcscheme | 3 +++ example/lib/main.dart | 9 +++++++++ lib/src/dots_indicator.dart | 10 ++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 8e3ca5d..e3773d4 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -26,6 +26,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit" shouldUseLaunchSchemeArgsEnv = "YES"> diff --git a/example/lib/main.dart b/example/lib/main.dart index 0357afd..9e2d385 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -215,6 +215,15 @@ class MyAppState extends State { animate: true, ), ]), + _buildRow([ + const Text('Active Previous Dot'), + DotsIndicator( + dotsCount: _totalDots, + position: _currentPosition, + activePreviousDot: true, + decorator: decorator, + ), + ]), ], ), ), diff --git a/lib/src/dots_indicator.dart b/lib/src/dots_indicator.dart index aa35b1a..e828852 100644 --- a/lib/src/dots_indicator.dart +++ b/lib/src/dots_indicator.dart @@ -29,6 +29,8 @@ class DotsIndicator extends StatelessWidget { /// Duration of the animation when the position changes. final Duration animationDuration; + final bool activePreviousDot; + DotsIndicator({ super.key, required this.dotsCount, @@ -43,6 +45,7 @@ class DotsIndicator extends StatelessWidget { this.fadeOutDistance = 0, this.animate = false, this.animationDuration = const Duration(milliseconds: 200), + this.activePreviousDot = false, }) : assert(dotsCount > 0, 'dotsCount must be superior to zero'), assert(position >= 0.0, 'position must be superior or equals to zero'), assert( @@ -99,7 +102,9 @@ class DotsIndicator extends StatelessWidget { final double absPositionIndexRelation = (position - index).abs(); final bool isCurrentlyVisible = absPositionIndexRelation <= fadeOutDistance; - final double lerpValue = min(1.0, absPositionIndexRelation).toDouble(); + final double lerpValue = activePreviousDot && index <= position + ? 0.0 // Set lerpValue to 0 for active state + : min(1.0, absPositionIndexRelation).toDouble(); Size size = Size.lerp( decorator.getActiveSize(index), @@ -142,7 +147,8 @@ class DotsIndicator extends StatelessWidget { : decorator.spacing, decoration: ShapeDecoration( color: Color.lerp( - decorator.getActiveColor(index) ?? Theme.of(context).primaryColor, + decorator.getActiveColor(index) ?? + Theme.of(context).primaryColor, decorator.getColor(index), lerpValue, ),