Skip to content

Commit f4a88fb

Browse files
faiyaz-shaikhSahil-Simform
authored andcommitted
feature: ✨ Tooltip action widget
- Added `toolTipAction` parameter in `Showcase` which is used to get action widget configuration and defaults to `null` - Added `DefaultToolTipActionWidget` class for default tooltip action widgets
1 parent c36c85a commit f4a88fb

File tree

5 files changed

+225
-109
lines changed

5 files changed

+225
-109
lines changed

example/lib/main.dart

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ class _MailPageState extends State<MailPage> {
235235
),
236236
child: Image.asset('assets/simform.png'),
237237
),
238+
toolTipAction: DefaultToolTipActionWidget(
239+
color: Colors.white,
240+
showCaseWidgetState: ShowCaseWidget.of(context),
241+
),
238242
),
239243
const SizedBox(
240244
width: 12,
@@ -314,27 +318,28 @@ class _MailPageState extends State<MailPage> {
314318
child: Container(
315319
padding: const EdgeInsets.symmetric(vertical: 8),
316320
child: Showcase(
317-
key: key,
318-
description: 'Tap to check mail',
319-
tooltipPosition: TooltipPosition.top,
320-
disposeOnTap: true,
321-
onTargetClick: () {
322-
Navigator.push<void>(
323-
context,
324-
MaterialPageRoute<void>(
325-
builder: (_) => const Detail(),
326-
),
327-
).then((_) {
328-
setState(() {
329-
ShowCaseWidget.of(context).startShowCase([_four, _five]);
330-
});
321+
key: key,
322+
description: 'Tap to check mail',
323+
tooltipPosition: TooltipPosition.top,
324+
disposeOnTap: true,
325+
onTargetClick: () {
326+
Navigator.push<void>(
327+
context,
328+
MaterialPageRoute<void>(
329+
builder: (_) => const Detail(),
330+
),
331+
).then((_) {
332+
setState(() {
333+
ShowCaseWidget.of(context).startShowCase([_four, _five]);
331334
});
332-
},
333-
child: MailTile(
334-
mail: mail,
335-
showCaseKey: _four,
336-
showCaseDetail: showCaseDetail,
337-
)),
335+
});
336+
},
337+
child: MailTile(
338+
mail: mail,
339+
showCaseKey: _four,
340+
showCaseDetail: showCaseDetail,
341+
),
342+
),
338343
),
339344
);
340345
}

lib/showcaseview.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ library showcaseview;
2525
export 'src/enum.dart';
2626
export 'src/showcase.dart';
2727
export 'src/showcase_widget.dart';
28+
export 'src/tooltip_action.dart';

lib/src/showcase.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import 'get_position.dart';
3232
import 'layout_overlays.dart';
3333
import 'shape_clipper.dart';
3434
import 'showcase_widget.dart';
35+
import 'tooltip_action.dart';
3536
import 'tooltip_widget.dart';
3637

3738
class Showcase extends StatefulWidget {
@@ -232,6 +233,11 @@ class Showcase extends StatefulWidget {
232233
/// Provides padding around the description. Default padding is zero.
233234
final EdgeInsets? descriptionPadding;
234235

236+
/// Provides tooTip action widgets at bottom in tool tip.
237+
///
238+
/// one can use [DefaultToolTipActionWidget] class to use default action
239+
final Widget? toolTipAction;
240+
235241
/// Provides text direction of tooltip title.
236242
final TextDirection? titleTextDirection;
237243

@@ -288,6 +294,7 @@ class Showcase extends StatefulWidget {
288294
this.tooltipPosition,
289295
this.titlePadding,
290296
this.descriptionPadding,
297+
this.toolTipAction,
291298
this.titleTextDirection,
292299
this.descriptionTextDirection,
293300
this.onBarrierClick,
@@ -350,6 +357,7 @@ class Showcase extends StatefulWidget {
350357
tooltipPadding = const EdgeInsets.symmetric(vertical: 8),
351358
titlePadding = null,
352359
descriptionPadding = null,
360+
toolTipAction = null,
353361
titleTextDirection = null,
354362
descriptionTextDirection = null,
355363
assert(overlayOpacity >= 0.0 && overlayOpacity <= 1.0,
@@ -619,6 +627,7 @@ class _ShowcaseState extends State<Showcase> {
619627
tooltipPosition: widget.tooltipPosition,
620628
titlePadding: widget.titlePadding,
621629
descriptionPadding: widget.descriptionPadding,
630+
toolTipAction: widget.toolTipAction,
622631
titleTextDirection: widget.titleTextDirection,
623632
descriptionTextDirection: widget.descriptionTextDirection,
624633
),

lib/src/tooltip_action.dart

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import 'package:flutter/material.dart';
2+
3+
import 'showcase_widget.dart';
4+
5+
/// Default Tooltip action Widget Nav
6+
/// Shows tooltip navigation and index / count elements if the conditions are
7+
/// indicated.
8+
class DefaultToolTipActionWidget extends StatelessWidget {
9+
const DefaultToolTipActionWidget({
10+
Key? key,
11+
required this.color,
12+
required this.showCaseWidgetState,
13+
this.padding = const EdgeInsets.only(top: 5),
14+
this.textStyle,
15+
this.iconSize,
16+
}) : super(key: key);
17+
18+
final Color? color;
19+
final ShowCaseWidgetState showCaseWidgetState;
20+
final EdgeInsets padding;
21+
final TextStyle? textStyle;
22+
final double? iconSize;
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
var ids = showCaseWidgetState.ids;
27+
var activeWidgetId = showCaseWidgetState.activeWidgetId;
28+
bool isFirstTip = activeWidgetId == 0;
29+
return Row(
30+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
31+
children: [
32+
GestureDetector(
33+
behavior: HitTestBehavior.translucent,
34+
onTap: (isFirstTip)
35+
? null
36+
: () {
37+
showCaseWidgetState.previous();
38+
},
39+
child: Padding(
40+
padding: padding,
41+
child: Icon(
42+
Icons.keyboard_arrow_left,
43+
size: iconSize,
44+
color: (isFirstTip)
45+
? color?.withOpacity(0.3) ?? Colors.black26
46+
: color,
47+
),
48+
),
49+
),
50+
if (ids != null && activeWidgetId != null) ...[
51+
const SizedBox(width: 4.0),
52+
Padding(
53+
padding: padding,
54+
child: Text(
55+
"${activeWidgetId + 1} / ${ids.length}",
56+
style: textStyle ??
57+
Theme.of(context).textTheme.bodyMedium?.copyWith(
58+
color: color,
59+
),
60+
),
61+
),
62+
const SizedBox(width: 4.0),
63+
],
64+
GestureDetector(
65+
behavior: HitTestBehavior.translucent,
66+
onTap: () {
67+
showCaseWidgetState.next();
68+
},
69+
child: Padding(
70+
padding: padding,
71+
child: Icon(
72+
Icons.keyboard_arrow_right,
73+
color: color,
74+
size: iconSize,
75+
),
76+
),
77+
),
78+
],
79+
);
80+
}
81+
}

0 commit comments

Comments
 (0)