initMethod method
void
initMethod()
Implementation
void initMethod() {
_widgetMax = widget.max;
_widgetMin = widget.min;
_touchSize = widget.touchSize ?? 15;
// validate inputs
_validations();
// to display min of the range correctly.
// if we use fakes, then min is always 0
// so calculations works well, but when we want to display
// result numbers to user, we add ( _widgetMin ) to the final numbers
// if(widget.axis == Axis.vertical) {
// animationStart = Offset(0.20, 0);
// animationFinish = Offset(-0.52, 0);
// }
if (__isInitCall) {
_leftHandlerScaleAnimationController = AnimationController(duration: widget.handlerAnimation.duration, vsync: this);
_rightHandlerScaleAnimationController = AnimationController(duration: widget.handlerAnimation.duration, vsync: this);
}
_leftHandlerScaleAnimation = Tween(
begin: 1.0,
end: widget.handlerAnimation.scale,
).animate(CurvedAnimation(
parent: _leftHandlerScaleAnimationController!,
reverseCurve: widget.handlerAnimation.reverseCurve,
curve: widget.handlerAnimation.curve,
));
_rightHandlerScaleAnimation = Tween(
begin: 1.0,
end: widget.handlerAnimation.scale,
).animate(CurvedAnimation(
parent: _rightHandlerScaleAnimationController!,
reverseCurve: widget.handlerAnimation.reverseCurve,
curve: widget.handlerAnimation.curve,
));
_setParameters();
_setValues();
if (widget.rangeSlider == true && widget.maximumDistance > 0 && (_upperValue! - _lowerValue!) > widget.maximumDistance) {
throw 'lower and upper distance is more than maximum distance';
}
if (widget.rangeSlider == true && widget.minimumDistance > 0 && (_upperValue! - _lowerValue!) < widget.minimumDistance) {
throw 'lower and upper distance is less than minimum distance';
}
Offset animationStart = const Offset(0, 0);
if (widget.tooltip?.disableAnimation == true) {
animationStart = const Offset(0, -1);
}
Offset? animationFinish;
switch (_tooltipData.direction) {
case FlutterSliderTooltipDirection.top:
animationFinish = const Offset(0, -1);
break;
case FlutterSliderTooltipDirection.left:
animationFinish = const Offset(-1, 0);
break;
case FlutterSliderTooltipDirection.right:
animationFinish = const Offset(1, 0);
break;
default:
animationFinish = Offset.zero;
break;
}
if (__isInitCall) {
_rightTooltipOpacity = (_tooltipData.alwaysShowTooltip == true) ? 1 : 0;
_leftTooltipOpacity = (_tooltipData.alwaysShowTooltip == true) ? 1 : 0;
_leftTooltipAnimationController = AnimationController(duration: const Duration(milliseconds: 200), vsync: this);
_rightTooltipAnimationController = AnimationController(duration: const Duration(milliseconds: 200), vsync: this);
} else {
if (_tooltipData.alwaysShowTooltip!) {
_rightTooltipOpacity = _leftTooltipOpacity = 1;
}
}
_leftTooltipAnimation = Tween<Offset>(begin: animationStart, end: animationFinish)
.animate(CurvedAnimation(parent: _leftTooltipAnimationController, curve: Curves.fastOutSlowIn));
_rightTooltipAnimation = Tween<Offset>(begin: animationStart, end: animationFinish)
.animate(CurvedAnimation(parent: _rightTooltipAnimationController, curve: Curves.fastOutSlowIn));
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) {
return;
}
_renderBoxInitialization();
_arrangeHandlersPosition();
_drawHatchMark();
setState(() {});
});
}