Skip to content

Commit

Permalink
Merge pull request #20 from jose-azevedo/set_default_values_for_Flutt…
Browse files Browse the repository at this point in the history
…erSliderTooltip

Set default values for flutter slider tooltip
  • Loading branch information
loonix authored Jan 9, 2023
2 parents 1dd43b3 + 7458eb9 commit a3ee36e
Showing 1 changed file with 39 additions and 43 deletions.
82 changes: 39 additions & 43 deletions lib/another_xlider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ class FlutterSliderState extends State<FlutterSlider>
}

Offset animationStart = const Offset(0, 0);
if (widget.tooltip != null &&
widget.tooltip!.disableAnimation != null &&
widget.tooltip!.disableAnimation!) {
if (widget.tooltip?.disableAnimation == true) {
animationStart = const Offset(0, -1);
}

Expand Down Expand Up @@ -421,7 +419,7 @@ class FlutterSliderState extends State<FlutterSlider>
_rightTooltipAnimationController = AnimationController(
duration: const Duration(milliseconds: 200), vsync: this);
} else {
if (_tooltipData.alwaysShowTooltip!) {
if (_tooltipData.alwaysShowTooltip) {
_rightTooltipOpacity = _leftTooltipOpacity = 1;
}
}
Expand Down Expand Up @@ -775,11 +773,10 @@ class FlutterSliderState extends State<FlutterSlider>
_tooltipData.leftSuffix = widgetTooltip.leftSuffix;
_tooltipData.rightPrefix = widgetTooltip.rightPrefix;
_tooltipData.rightSuffix = widgetTooltip.rightSuffix;
_tooltipData.alwaysShowTooltip = widgetTooltip.alwaysShowTooltip ?? false;
_tooltipData.disabled = widgetTooltip.disabled ?? false;
_tooltipData.disableAnimation = widgetTooltip.disableAnimation ?? false;
_tooltipData.direction =
widgetTooltip.direction ?? FlutterSliderTooltipDirection.top;
_tooltipData.alwaysShowTooltip = widgetTooltip.alwaysShowTooltip;
_tooltipData.disabled = widgetTooltip.disabled;
_tooltipData.disableAnimation = widgetTooltip.disableAnimation;
_tooltipData.direction = widgetTooltip.direction;
_tooltipData.positionOffset = widgetTooltip.positionOffset;
_tooltipData.format = widgetTooltip.format;
_tooltipData.custom = widgetTooltip.custom;
Expand Down Expand Up @@ -1523,7 +1520,7 @@ class FlutterSliderState extends State<FlutterSlider>
xDragTmp = (_.position.dx - _containerLeft - _leftHandlerXPosition!);
yDragTmp = (_.position.dy - _containerTop - _leftHandlerYPosition!);

if (!_tooltipData.disabled! &&
if (!_tooltipData.disabled &&
_tooltipData.alwaysShowTooltip == false) {
_leftTooltipOpacity = 1;
_leftTooltipAnimationController.forward();
Expand Down Expand Up @@ -1592,7 +1589,7 @@ class FlutterSliderState extends State<FlutterSlider>
}

void _hideTooltips() {
if (!_tooltipData.alwaysShowTooltip!) {
if (!_tooltipData.alwaysShowTooltip) {
_leftTooltipOpacity = 0;
_rightTooltipOpacity = 0;
_leftTooltipAnimationController.reset();
Expand Down Expand Up @@ -1635,7 +1632,7 @@ class FlutterSliderState extends State<FlutterSlider>
onPointerMove: (_) {
__dragging = true;

if (!_tooltipData.disabled! &&
if (!_tooltipData.disabled &&
_tooltipData.alwaysShowTooltip == false) {
_rightTooltipOpacity = 1;
}
Expand All @@ -1652,7 +1649,7 @@ class FlutterSliderState extends State<FlutterSlider>
xDragTmp = (_.position.dx - _containerLeft - _rightHandlerXPosition!);
yDragTmp = (_.position.dy - _containerTop - _rightHandlerYPosition!);

if (!_tooltipData.disabled! &&
if (!_tooltipData.disabled &&
_tooltipData.alwaysShowTooltip == false) {
_rightTooltipOpacity = 1;
_rightTooltipAnimationController.forward();
Expand Down Expand Up @@ -1817,7 +1814,7 @@ class FlutterSliderState extends State<FlutterSlider>
if (widget.rangeSlider) {
if (_leftTapAndSlide) {
_trackBarSlideCallDragStated(0);
if (!_tooltipData.disabled! &&
if (!_tooltipData.disabled &&
_tooltipData.alwaysShowTooltip == false) {
_leftTooltipOpacity = 1;
_leftTooltipAnimationController.forward();
Expand All @@ -1826,7 +1823,7 @@ class FlutterSliderState extends State<FlutterSlider>
tappedPositionWithPadding: tappedPositionWithPadding);
} else {
_trackBarSlideCallDragStated(1);
if (!_tooltipData.disabled! &&
if (!_tooltipData.disabled &&
_tooltipData.alwaysShowTooltip == false) {
_rightTooltipOpacity = 1;
_rightTooltipAnimationController.forward();
Expand All @@ -1836,7 +1833,7 @@ class FlutterSliderState extends State<FlutterSlider>
}
} else {
_trackBarSlideCallDragStated(1);
if (!_tooltipData.disabled! &&
if (!_tooltipData.disabled &&
_tooltipData.alwaysShowTooltip == false) {
_rightTooltipOpacity = 1;
_rightTooltipAnimationController.forward();
Expand Down Expand Up @@ -1929,7 +1926,7 @@ class FlutterSliderState extends State<FlutterSlider>

if (_ignoreSteps.isEmpty) {
if ((widget.lockHandlers || __lockedHandlersDragOffset > 0) &&
!_tooltipData.disabled! &&
!_tooltipData.disabled &&
_tooltipData.alwaysShowTooltip == false) {
_leftTooltipOpacity = 1;
_leftTooltipAnimationController.forward();
Expand Down Expand Up @@ -1983,7 +1980,7 @@ class FlutterSliderState extends State<FlutterSlider>

Positioned _tooltip(
{String? side, dynamic value, double? opacity, Animation? animation}) {
if (_tooltipData.disabled! || value == '') {
if (_tooltipData.disabled || value == '') {
return Positioned(
child: Container(),
);
Expand Down Expand Up @@ -2027,25 +2024,24 @@ class FlutterSliderState extends State<FlutterSlider>
}

Widget tooltipWidget = IgnorePointer(
child: Center(
child: FittedBox(
child: Container(
// height: ,
// height: __tooltipKEY.currentContext.size.height,
key: (side == 'left') ? leftTooltipKey : rightTooltipKey,
// alignment: Alignment.center,
child: (widget.tooltip != null && widget.tooltip!.custom != null)
? widget.tooltip!.custom!(value)
: Container(
padding: const EdgeInsets.all(8),
decoration: _tooltipData.boxStyle!.decoration,
foregroundDecoration:
_tooltipData.boxStyle!.foregroundDecoration,
transform: _tooltipData.boxStyle!.transform,
child: tooltipHolderWidget),
child: Center(
child: FittedBox(
child: Container(
key: (side == 'left') ? leftTooltipKey : rightTooltipKey,
child: (widget.tooltip != null && widget.tooltip!.custom != null)
? widget.tooltip!.custom!(value)
: Container(
padding: const EdgeInsets.all(8),
decoration: _tooltipData.boxStyle!.decoration,
foregroundDecoration:
_tooltipData.boxStyle!.foregroundDecoration,
transform: _tooltipData.boxStyle!.transform,
child: tooltipHolderWidget,
),
),
),
),
));
);

double? top, right, bottom, left;
switch (_tooltipData.direction) {
Expand Down Expand Up @@ -2440,10 +2436,10 @@ class FlutterSliderTooltip {
Widget? leftSuffix;
Widget? rightPrefix;
Widget? rightSuffix;
bool? alwaysShowTooltip;
bool? disabled;
bool? disableAnimation;
FlutterSliderTooltipDirection? direction;
bool alwaysShowTooltip;
bool disabled;
bool disableAnimation;
FlutterSliderTooltipDirection direction;
FlutterSliderTooltipPositionOffset? positionOffset;

FlutterSliderTooltip({
Expand All @@ -2455,10 +2451,10 @@ class FlutterSliderTooltip {
this.leftSuffix,
this.rightPrefix,
this.rightSuffix,
this.alwaysShowTooltip,
this.disableAnimation,
this.disabled,
this.direction,
this.alwaysShowTooltip = false,
this.disableAnimation = false,
this.disabled = false,
this.direction = FlutterSliderTooltipDirection.top,
this.positionOffset,
});

Expand Down

0 comments on commit a3ee36e

Please sign in to comment.