Skip to content
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

add min and max limitation for step #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions lib/src/stepper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ class StepperTouch extends StatefulWidget {
this.counterColor = const Color(0xFF6D72FF),
this.dragButtonColor = Colors.white,
this.buttonsColor = Colors.white,
this.decraseLimaition=double.negativeInfinity,
this.increaseLimaition=double.infinity,

}) : super(key: key);

/// the orientation of the stepper its horizontal or vertical.
final Axis direction;

/// the limit of decrease
final double decraseLimaition;

/// the limit of decrease
final double increaseLimaition;
/// the initial value of the stepper
final int initialValue;

Expand All @@ -45,6 +53,7 @@ class _Stepper2State extends State<StepperTouch>
double _startAnimationPosX;
double _startAnimationPosY;


@override
void initState() {
super.initState();
Expand Down Expand Up @@ -99,7 +108,7 @@ class _Stepper2State extends State<StepperTouch>
left: widget.direction == Axis.horizontal ? 10.0 : null,
bottom: widget.direction == Axis.horizontal ? null : 10.0,
child:
Icon(Icons.remove, size: 40.0, color: widget.buttonsColor),
Icon(Icons.remove, size: 40.0, color: widget.buttonsColor),
),
Positioned(
right: widget.direction == Axis.horizontal ? 10.0 : null,
Expand Down Expand Up @@ -168,15 +177,15 @@ class _Stepper2State extends State<StepperTouch>
bool isHor = widget.direction == Axis.horizontal;
bool changed = false;
if (_controller.value <= -0.20) {
setState(() => isHor ? _value-- : _value++);
setState(() => isHor ? widget.increaseLimaition==double.infinity? _value--: _value==widget.decraseLimaition.toInt()?_value=0: _value-- :widget.increaseLimaition==double.infinity? _value++ : _value==widget.increaseLimaition.toInt()?_value: _value++);
changed = true;
} else if (_controller.value >= 0.20) {
setState(() => isHor ? _value++ : _value--);
setState(() => isHor ? widget.increaseLimaition==double.infinity? _value++ : _value==widget.increaseLimaition.toInt()?_value: _value++ :widget.increaseLimaition==double.infinity? _value--: _value==widget.decraseLimaition.toInt()?_value=0: _value--);
changed = true;
}
if (widget.withSpring) {
final SpringDescription _kDefaultSpring =
new SpringDescription.withDampingRatio(
new SpringDescription.withDampingRatio(
mass: 0.9,
stiffness: 250.0,
ratio: 0.6,
Expand Down