From 7faf0589b0452e5446e3e663542661a8da17eebe Mon Sep 17 00:00:00 2001 From: Praharsh Bhatt <30700808+praharshbhatt@users.noreply.github.com> Date: Wed, 11 Mar 2020 22:24:10 +0530 Subject: [PATCH] Added colors Added primaryColor and textColor; --- lib/src/stepper.dart | 74 +++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/lib/src/stepper.dart b/lib/src/stepper.dart index ea89e2d..0112644 100644 --- a/lib/src/stepper.dart +++ b/lib/src/stepper.dart @@ -5,16 +5,15 @@ import 'package:flutter/physics.dart'; /// from [Nikolay Kuchkarov](https://dribbble.com/shots/3368130-Stepper-Touch). /// i extended the functionality to be more useful in real world applications class StepperTouch extends StatefulWidget { - const StepperTouch({ - Key key, - this.initialValue, - this.onChanged, - this.direction = Axis.horizontal, - this.withSpring = true, - this.counterColor = const Color(0xFF6D72FF), - this.dragButtonColor = Colors.white, - this.buttonsColor = Colors.white, - }) : super(key: key); + const StepperTouch( + {Key key, + this.initialValue, + this.onChanged, + this.direction = Axis.horizontal, + this.withSpring = true, + this.primaryColor = const Color(0xFF6D72FF), + this.textColor = const Color(0xFF6D72FF)}) + : super(key: key); /// the orientation of the stepper its horizontal or vertical. final Axis direction; @@ -22,6 +21,9 @@ class StepperTouch extends StatefulWidget { /// the initial value of the stepper final int initialValue; + ///For Color + final primaryColor, textColor; + /// called whenever the value of the stepper changed final ValueChanged onChanged; @@ -29,16 +31,11 @@ class StepperTouch extends StatefulWidget { /// defaults to true final bool withSpring; - final Color counterColor; - final Color dragButtonColor; - final Color buttonsColor; - @override _Stepper2State createState() => _Stepper2State(); } -class _Stepper2State extends State - with SingleTickerProviderStateMixin { +class _Stepper2State extends State with SingleTickerProviderStateMixin { AnimationController _controller; Animation _animation; int _value; @@ -49,17 +46,14 @@ class _Stepper2State extends State void initState() { super.initState(); _value = widget.initialValue ?? 0; - _controller = - AnimationController(vsync: this, lowerBound: -0.5, upperBound: 0.5); + _controller = AnimationController(vsync: this, lowerBound: -0.5, upperBound: 0.5); _controller.value = 0.0; _controller.addListener(() {}); if (widget.direction == Axis.horizontal) { - _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(1.5, 0.0)) - .animate(_controller); + _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(1.5, 0.0)).animate(_controller); } else { - _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(0.0, 1.5)) - .animate(_controller); + _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(0.0, 1.5)).animate(_controller); } } @@ -73,11 +67,9 @@ class _Stepper2State extends State void didUpdateWidget(oldWidget) { super.didUpdateWidget(oldWidget); if (widget.direction == Axis.horizontal) { - _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(1.5, 0.0)) - .animate(_controller); + _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(1.5, 0.0)).animate(_controller); } else { - _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(0.0, 1.5)) - .animate(_controller); + _animation = Tween(begin: Offset(0.0, 0.0), end: Offset(0.0, 1.5)).animate(_controller); } } @@ -91,20 +83,19 @@ class _Stepper2State extends State type: MaterialType.canvas, clipBehavior: Clip.antiAlias, borderRadius: BorderRadius.circular(60.0), - color: Colors.white.withOpacity(0.2), + color: widget.primaryColor.withOpacity(0.2), child: Stack( alignment: Alignment.center, children: [ Positioned( 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), + child: Icon(Icons.remove, size: 40.0, color: widget.primaryColor), ), Positioned( right: widget.direction == Axis.horizontal ? 10.0 : null, top: widget.direction == Axis.horizontal ? null : 10.0, - child: Icon(Icons.add, size: 40.0, color: widget.buttonsColor), + child: Icon(Icons.add, size: 40.0, color: widget.primaryColor), ), GestureDetector( onHorizontalDragStart: _onPanStart, @@ -113,22 +104,19 @@ class _Stepper2State extends State child: SlideTransition( position: _animation, child: Material( - color: widget.dragButtonColor, + color: widget.primaryColor, shape: const CircleBorder(), elevation: 5.0, child: Center( child: AnimatedSwitcher( duration: const Duration(milliseconds: 500), - transitionBuilder: - (Widget child, Animation animation) { - return ScaleTransition( - child: child, scale: animation); + transitionBuilder: (Widget child, Animation animation) { + return ScaleTransition(child: child, scale: animation); }, child: Text( '$_value', key: ValueKey(_value), - style: TextStyle( - color: widget.counterColor, fontSize: 56.0), + style: TextStyle(color: widget.textColor, fontSize: 56.0), ), ), ), @@ -175,22 +163,18 @@ class _Stepper2State extends State changed = true; } if (widget.withSpring) { - final SpringDescription _kDefaultSpring = - new SpringDescription.withDampingRatio( + final SpringDescription _kDefaultSpring = new SpringDescription.withDampingRatio( mass: 0.9, stiffness: 250.0, ratio: 0.6, ); if (widget.direction == Axis.horizontal) { - _controller.animateWith( - SpringSimulation(_kDefaultSpring, _startAnimationPosX, 0.0, 0.0)); + _controller.animateWith(SpringSimulation(_kDefaultSpring, _startAnimationPosX, 0.0, 0.0)); } else { - _controller.animateWith( - SpringSimulation(_kDefaultSpring, _startAnimationPosY, 0.0, 0.0)); + _controller.animateWith(SpringSimulation(_kDefaultSpring, _startAnimationPosY, 0.0, 0.0)); } } else { - _controller.animateTo(0.0, - curve: Curves.bounceOut, duration: Duration(milliseconds: 500)); + _controller.animateTo(0.0, curve: Curves.bounceOut, duration: Duration(milliseconds: 500)); } if (changed && widget.onChanged != null) {