From f4e7dd2361e037861d7ae68514d71e29904d0e14 Mon Sep 17 00:00:00 2001 From: Abu Bakr Ibrahim Ataa Date: Sat, 16 May 2020 17:09:56 -0700 Subject: [PATCH 1/2] add min and max limitation for step A parameter where the Minimum and Maximum Value for the widget could be passed. Thereby giving a lower and upper bound to the Stepper Touch widget. For example for a value less than 0, the widget will disable the subtraction function. --- lib/src/stepper.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/src/stepper.dart b/lib/src/stepper.dart index ea89e2d..312fb4f 100644 --- a/lib/src/stepper.dart +++ b/lib/src/stepper.dart @@ -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; @@ -45,6 +53,7 @@ class _Stepper2State extends State double _startAnimationPosX; double _startAnimationPosY; + @override void initState() { super.initState(); @@ -99,7 +108,7 @@ class _Stepper2State extends State 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, @@ -168,15 +177,15 @@ class _Stepper2State extends State bool isHor = widget.direction == Axis.horizontal; bool changed = false; if (_controller.value <= -0.20) { - setState(() => isHor ? _value-- : _value++); + setState(() => isHor ? _value==widget.decraseLimaition.toInt()?_value=0: _value-- : _value==widget.increaseLimaition.toInt()?_value: _value++); changed = true; } else if (_controller.value >= 0.20) { - setState(() => isHor ? _value++ : _value--); + setState(() => isHor ? _value==widget.increaseLimaition.toInt()?_value: _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, From 8eca6bf7bcea442e729a8a8a58927db1e0bb6b72 Mon Sep 17 00:00:00 2001 From: Abu Bakr Ibrahim Ataa Date: Sat, 16 May 2020 17:26:26 -0700 Subject: [PATCH 2/2] fix bugs if no parmater for increase or decrease limition --- lib/src/stepper.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/stepper.dart b/lib/src/stepper.dart index 312fb4f..4a1d59d 100644 --- a/lib/src/stepper.dart +++ b/lib/src/stepper.dart @@ -177,10 +177,10 @@ class _Stepper2State extends State bool isHor = widget.direction == Axis.horizontal; bool changed = false; if (_controller.value <= -0.20) { - setState(() => isHor ? _value==widget.decraseLimaition.toInt()?_value=0: _value-- : _value==widget.increaseLimaition.toInt()?_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==widget.increaseLimaition.toInt()?_value: _value++ : _value==widget.decraseLimaition.toInt()?_value=0: _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) {