Skip to content

feat: add activePreviousDot option to highlight previous dots #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
Expand Down Expand Up @@ -54,11 +55,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
9 changes: 9 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ class MyAppState extends State<MyApp> {
animate: true,
),
]),
_buildRow([
const Text('Active Previous Dot'),
DotsIndicator(
dotsCount: _totalDots,
position: _currentPosition,
activePreviousDot: true,
decorator: decorator,
),
]),
],
),
),
Expand Down
10 changes: 8 additions & 2 deletions lib/src/dots_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
),
Expand Down