Skip to content

Commit

Permalink
🐛 Fixed ToolTip Slide Transition
Browse files Browse the repository at this point in the history
  • Loading branch information
faiyaz-shaikh committed Apr 6, 2023
1 parent 5495cee commit 92e21f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
10 changes: 10 additions & 0 deletions lib/src/showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ class Showcase extends StatefulWidget {
/// will still provide a callback.
final VoidCallback? onBarrierClick;

/// Define End distance of tooltip position when tooltip is moving.
///
/// Which is from 0 to movingEndDistance (positive)
///
/// Default to '7.0'
final double movingEndDistance;

const Showcase({
required this.key,
required this.description,
Expand Down Expand Up @@ -288,6 +295,7 @@ class Showcase extends StatefulWidget {
this.titleTextDirection,
this.descriptionTextDirection,
this.onBarrierClick,
this.movingEndDistance = 7.0,
}) : height = null,
width = null,
container = null,
Expand Down Expand Up @@ -325,6 +333,7 @@ class Showcase extends StatefulWidget {
this.disableDefaultTargetGestures = false,
this.tooltipPosition,
this.onBarrierClick,
this.movingEndDistance = 7.0,
}) : showArrow = false,
onToolTipClick = null,
scaleAnimationDuration = const Duration(milliseconds: 300),
Expand Down Expand Up @@ -573,6 +582,7 @@ class _ShowcaseState extends State<Showcase> {
descriptionPadding: widget.descriptionPadding,
titleTextDirection: widget.titleTextDirection,
descriptionTextDirection: widget.descriptionTextDirection,
movingEndDistance: widget.movingEndDistance,
),
],
],
Expand Down
42 changes: 29 additions & 13 deletions lib/src/tooltip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ToolTipWidget extends StatefulWidget {
final EdgeInsets? descriptionPadding;
final TextDirection? titleTextDirection;
final TextDirection? descriptionTextDirection;
final double movingEndDistance;

const ToolTipWidget({
Key? key,
Expand Down Expand Up @@ -94,6 +95,7 @@ class ToolTipWidget extends StatefulWidget {
this.descriptionPadding,
this.titleTextDirection,
this.descriptionTextDirection,
this.movingEndDistance = 7.0,
}) : super(key: key);

@override
Expand Down Expand Up @@ -337,7 +339,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
contentOffsetMultiplier.clamp(-1.0, 0.0);

var paddingTop = isArrowUp ? 22.0 : 0.0;
var paddingBottom = isArrowUp ? 0.0 : 27.0;
var paddingBottom = isArrowUp ? 0.0 : 22.0;

if (!widget.showArrow) {
paddingTop = 10;
Expand Down Expand Up @@ -365,10 +367,11 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
),
child: FractionalTranslation(
translation: Offset(0.0, contentFractionalOffset as double),
child: SlideTransition(
child: ToolTipSlideTransition(
position: Tween<Offset>(
begin: Offset(0.0, contentFractionalOffset / 10),
end: const Offset(0.0, 0.100),
begin: const Offset(0.0, 0.0),
end: Offset(
0.0, widget.movingEndDistance * contentOffsetMultiplier),
).animate(_movingAnimation),
child: Material(
type: MaterialType.transparency,
Expand Down Expand Up @@ -480,24 +483,22 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
children: <Widget>[
Positioned(
left: _getSpace(),
top: contentY - 10,
top: contentY - (10.0 * contentOffsetMultiplier),
child: FractionalTranslation(
translation: Offset(0.0, contentFractionalOffset as double),
child: SlideTransition(
child: ToolTipSlideTransition(
position: Tween<Offset>(
begin: Offset(0.0, contentFractionalOffset / 10),
end: !widget.showArrow && !isArrowUp
? const Offset(0.0, 0.0)
: const Offset(0.0, 0.100),
begin: const Offset(0.0, 0.0),
end: Offset(
0.0, widget.movingEndDistance * contentOffsetMultiplier),
).animate(_movingAnimation),
child: Material(
color: Colors.transparent,
child: GestureDetector(
onTap: widget.onTooltipTap,
child: Container(
padding: EdgeInsets.only(
top: paddingTop,
),
padding:
EdgeInsets.only(top: paddingTop, bottom: paddingBottom),
color: Colors.transparent,
child: Center(
child: MeasureSize(
Expand Down Expand Up @@ -589,3 +590,18 @@ class _Arrow extends CustomPainter {
oldDelegate.strokeWidth != strokeWidth;
}
}

class ToolTipSlideTransition extends AnimatedWidget {
const ToolTipSlideTransition({
required Listenable position,
required this.child,
}) : super(listenable: position);

final Widget child;

Animation<Offset> get _progress => listenable as Animation<Offset>;

@override
Widget build(BuildContext context) =>
Transform.translate(offset: _progress.value, child: child);
}

0 comments on commit 92e21f5

Please sign in to comment.