Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tip navigation: New optional navigation options for the Showcase() widget #273

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixed some bugs for the position of the end icon at different screen …
…sizes / content widths. Now works for all situations.

Incorporated latest changes from repository master.
  • Loading branch information
mdrideout committed Sep 26, 2022
commit f1c6b27b42565aaf50257fcbed83a17038962eb5
191 changes: 109 additions & 82 deletions lib/src/tooltip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import 'measure_size.dart';
import 'tooltip_widget_nav.dart';

const _kDefaultPaddingFromParent = 14.0;
const _kEndIconPaddingAll = 2.0;
const _kEndIconSize = 16.0;
const _kEndIconTotalWidth = _kEndIconSize + _kEndIconPaddingAll;
const _kMinRightPaddingIfEndIconEnabled = 2.0;

class ToolTipWidget extends StatefulWidget {
final GlobalKey globalKey;
Expand Down Expand Up @@ -140,6 +144,9 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
widget.contentPadding!.right +
widget.contentPadding!.left);
var maxTextWidth = max(titleLength, descriptionLength);
if (widget.showEndIcon) {
maxTextWidth += _kEndIconTotalWidth;
}
if (maxTextWidth > widget.screenSize!.width - tooltipScreenEdgePadding) {
tooltipWidth = widget.screenSize!.width - tooltipScreenEdgePadding;
} else {
Expand All @@ -165,10 +172,16 @@ class _ToolTipWidgetState extends State<ToolTipWidget>

double? _getRight() {
if (widget.position != null) {
debugPrint("This condition");
var rightPosition = widget.position!.getCenter() + (tooltipWidth * 0.5);

// Accommodate end icon offset width if enabled
double minRightPadding = (widget.showEndIcon)
? _kMinRightPaddingIfEndIconEnabled
: _kDefaultPaddingFromParent;

return (rightPosition + tooltipWidth) > MediaQuery.of(context).size.width
? _kDefaultPaddingFromParent
? minRightPadding
: null;
}
return null;
Expand Down Expand Up @@ -226,6 +239,9 @@ class _ToolTipWidgetState extends State<ToolTipWidget>

@override
Widget build(BuildContext context) {
debugPrint("Left: ${_getLeft()}");
debugPrint("Right: ${_getRight()}");

position = widget.offset;
final contentOrientation = findPositionForContent(position!);
final contentOffsetMultiplier = contentOrientation == "BELOW" ? 1.0 : -1.0;
Expand All @@ -249,9 +265,6 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
const arrowWidth = 18.0;
const arrowHeight = 9.0;
const defaultBorderRadius = 8.0;
const endIconPaddingAll = 2.0;
const endIconSize = 16.0;
const endIconTotalWidth = endIconSize + endIconPaddingAll;

if (widget.container == null) {
return Positioned(
Expand Down Expand Up @@ -311,98 +324,112 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
padding: EdgeInsets.only(
top: isArrowUp ? arrowHeight - 1 : 0,
bottom: isArrowUp ? 0 : arrowHeight - 1,
right:
(widget.showEndIcon) ? (endIconTotalWidth) / 2 : 0,
),
child: ClipRRect(
borderRadius: widget.borderRadius ??
BorderRadius.circular(defaultBorderRadius),
child: GestureDetector(
onTap: widget.onTooltipTap,
child: Container(
width: tooltipWidth,
padding: widget.contentPadding,
color: widget.tooltipColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
crossAxisAlignment: widget.title != null
? CrossAxisAlignment.start
: CrossAxisAlignment.center,
children: <Widget>[
widget.title != null
? Text(
widget.title!,
style: widget.titleTextStyle ??
child: Stack(
children: [
Padding(
// Conditional container padding to accommodate an offset endIcon
padding: EdgeInsets.only(
right: (widget.showEndIcon)
? _kEndIconTotalWidth / 2
: 0),
child: ClipRRect(
borderRadius: widget.borderRadius ??
BorderRadius.circular(defaultBorderRadius),
child: GestureDetector(
onTap: widget.onTooltipTap,
child: Container(
width: tooltipWidth,
padding: widget.contentPadding,
color: widget.tooltipColor,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
children: <Widget>[
Column(
crossAxisAlignment: widget.title != null
? CrossAxisAlignment.start
: CrossAxisAlignment.center,
children: <Widget>[
widget.title != null
? Text(
widget.title!,
style:
widget.titleTextStyle ??
Theme.of(context)
.textTheme
.headline6!
.merge(
TextStyle(
color: widget
.textColor,
),
),
)
: const SizedBox(),
Text(
widget.description!,
style: widget.descTextStyle ??
Theme.of(context)
.textTheme
.headline6!
.subtitle2!
.merge(
TextStyle(
color: widget.textColor,
),
),
),
TooltipWidgetNav(
globalKey: widget.globalKey,
showForwardBackNav:
widget.showForwardBackNav,
showTipCountIndex:
widget.showTipCountIndex,
textColor: widget.textColor,
)
: const SizedBox(),
Text(
widget.description!,
style: widget.descTextStyle ??
Theme.of(context)
.textTheme
.subtitle2!
.merge(
TextStyle(
color: widget.textColor,
),
),
),
TooltipWidgetNav(
globalKey: widget.globalKey,
showForwardBackNav:
widget.showForwardBackNav,
showTipCountIndex:
widget.showTipCountIndex,
textColor: widget.textColor,
)
],
)
],
],
)
],
),
),
),
),
),
),
),
),
if (widget.showEndIcon)
Positioned(
right: 0,
top: (isArrowUp) ? arrowHeight - 1 : 0,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
debugPrint("End");
ShowCaseWidget.of(widget.globalKey.currentContext!)
.dismiss();
},
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.zero,
topRight: Radius.circular(50),
bottomRight: Radius.circular(50),
bottomLeft: Radius.circular(50),
),
child: Container(
padding: const EdgeInsets.all(endIconPaddingAll),
color: widget.tooltipColor,
child: Icon(
Icons.close,
size: endIconSize,
color: widget.textColor,
if (widget.showEndIcon)
Positioned(
right: 0,
top: (isArrowUp) ? arrowHeight - 1 : 0,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
debugPrint("End");
ShowCaseWidget.of(
widget.globalKey.currentContext!)
.dismiss();
},
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.zero,
topRight: Radius.circular(50),
bottomRight: Radius.circular(50),
bottomLeft: Radius.circular(50),
),
child: Container(
padding: const EdgeInsets.all(
_kEndIconPaddingAll),
color: widget.tooltipColor,
child: Icon(
Icons.close,
size: _kEndIconSize,
color: widget.textColor,
),
),
),
),
),
),
),
],
),
),
],
),
),
Expand Down