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
Updated tooltip_widget_nav elements to be better sized and spaced. Ad…
…ded optional showEndIcon.
  • Loading branch information
mdrideout committed Sep 26, 2022
commit 6b792fa378e5008f052f7b9e84f68f961fdbb5e9
38 changes: 35 additions & 3 deletions lib/src/tooltip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'dart:math';

import 'package:flutter/material.dart';

import '../showcaseview.dart';
import 'get_position.dart';
import 'measure_size.dart';
import 'tooltip_widget_nav.dart';
Expand Down Expand Up @@ -247,6 +248,10 @@ 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 @@ -306,10 +311,12 @@ 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(8.0),
borderRadius: widget.borderRadius ??
BorderRadius.circular(defaultBorderRadius),
child: GestureDetector(
onTap: widget.onTooltipTap,
child: Container(
Expand Down Expand Up @@ -356,7 +363,6 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
widget.showForwardBackNav,
showTipCountIndex:
widget.showTipCountIndex,
showEndIcon: widget.showEndIcon,
textColor: widget.textColor,
)
],
Expand All @@ -367,6 +373,32 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
),
),
),
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: const Icon(Icons.close, size: endIconSize),
),
),
),
),
],
),
),
Expand Down
38 changes: 25 additions & 13 deletions lib/src/tooltip_widget_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ class TooltipWidgetNav extends StatelessWidget {
final GlobalKey globalKey;
final bool showForwardBackNav;
final bool showTipCountIndex;
final bool showEndIcon;
final Color? textColor;
const TooltipWidgetNav({
Key? key,
required this.globalKey,
required this.showForwardBackNav,
required this.showTipCountIndex,
required this.showEndIcon,
required this.textColor,
}) : super(key: key);

Expand All @@ -34,34 +32,48 @@ class TooltipWidgetNav extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (showForwardBackNav)
IconButton(
GestureDetector(
behavior: HitTestBehavior.translucent,

// Disable if activeWidgetId (index) == 0
onPressed: (isFirstTip)
onTap: (isFirstTip)
? null
: () {
ShowCaseWidget.of(globalKey.currentContext!)
.previous();
},
icon: Icon(
Icons.keyboard_arrow_left,
color: (isFirstTip) ? null : textColor,
child: Padding(
padding: const EdgeInsets.only(right: 8.0, top: 4.0),
child: Icon(
Icons.keyboard_arrow_left,
color: (isFirstTip)
? textColor?.withOpacity(0.3) ?? Colors.black26
: textColor,
),
),
),
if (showTipCountIndex &&
ids != null &&
activeWidgetId != null) ...[
const SizedBox(width: 4.0),
Text("${activeWidgetId + 1} / ${ids.length}"),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Text("${activeWidgetId + 1} / ${ids.length}"),
),
const SizedBox(width: 4.0),
],
if (showForwardBackNav)
IconButton(
onPressed: () {
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
ShowCaseWidget.of(globalKey.currentContext!).next();
},
icon: Icon(
Icons.keyboard_arrow_right,
color: textColor,
child: Padding(
padding: const EdgeInsets.only(left: 8.0, top: 4.0),
child: Icon(
Icons.keyboard_arrow_right,
color: textColor,
),
),
),
],
Expand Down