Skip to content

Commit f5ea659

Browse files
committed
fix: 🔨Fixed PR comments
1 parent c55862f commit f5ea659

File tree

9 files changed

+333
-261
lines changed

9 files changed

+333
-261
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,31 @@ To show multiple showcase at the same time provide same key to showcase.
130130
Note: auto scroll to showcase will not work in case of the multi-showcase and we will use property
131131
of first initialized showcase for common things like barrier tap and colors.
132132

133+
```dart
134+
GlobalKey _one = GlobalKey();
135+
...
136+
137+
Showcase(
138+
key: _one,
139+
title: 'Showcase one',
140+
description: 'Click here to see menu options',
141+
child: Icon(
142+
Icons.menu,
143+
color: Colors.black45,
144+
),
145+
),
146+
147+
Showcase(
148+
key: _one,
149+
title: 'Showcase two',
150+
description: 'Click here to see menu options',
151+
child: Icon(
152+
Icons.menu,
153+
color: Colors.black45,
154+
),
155+
),
156+
```
157+
133158
## Functions of `ShowCaseWidget.of(context)`:
134159

135160
| Function Name | Description |

example/lib/main.dart

Lines changed: 85 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:developer';
23

34
import 'package:example/detailscreen.dart';
@@ -18,80 +19,89 @@ class MyApp extends StatelessWidget {
1819

1920
@override
2021
Widget build(BuildContext context) {
21-
return MaterialApp(
22-
title: 'Flutter ShowCase',
23-
theme: ThemeData(
24-
primaryColor: const Color(0xffEE5366),
25-
),
26-
debugShowCheckedModeBanner: false,
27-
home: Scaffold(
28-
body: ShowCaseWidget(
29-
hideFloatingActionWidgetForShowcase: [_lastShowcaseWidget],
30-
globalFloatingActionWidget: (showcaseContext) => FloatingActionWidget(
31-
left: 16,
32-
bottom: 16,
33-
child: Padding(
34-
padding: const EdgeInsets.all(16.0),
35-
child: ElevatedButton(
36-
onPressed: ShowCaseWidget.of(showcaseContext).dismiss,
37-
style: ElevatedButton.styleFrom(
38-
backgroundColor: const Color(0xffEE5366),
22+
return Padding(
23+
padding: const EdgeInsets.all(50),
24+
child: MaterialApp(
25+
title: 'Flutter ShowCase',
26+
theme: ThemeData(
27+
primaryColor: const Color(0xffEE5366),
28+
),
29+
debugShowCheckedModeBanner: false,
30+
home: Scaffold(
31+
floatingActionButton: SizedBox(
32+
height: 400,
33+
width: 400,
34+
child: ShowCaseWidget(
35+
hideFloatingActionWidgetForShowcase: [_lastShowcaseWidget],
36+
enableAutoScroll: true,
37+
globalFloatingActionWidget: (showcaseContext) =>
38+
FloatingActionWidget(
39+
left: 16,
40+
bottom: 16,
41+
child: Padding(
42+
padding: const EdgeInsets.all(16.0),
43+
child: ElevatedButton(
44+
onPressed: ShowCaseWidget.of(showcaseContext).dismiss,
45+
style: ElevatedButton.styleFrom(
46+
backgroundColor: const Color(0xffEE5366),
47+
),
48+
child: const Text(
49+
'Skip',
50+
style: TextStyle(
51+
color: Colors.white,
52+
fontSize: 15,
53+
),
54+
),
55+
),
3956
),
40-
child: const Text(
41-
'Skip',
42-
style: TextStyle(
57+
),
58+
onStart: (index, key) {
59+
log('onStart: $index, $key');
60+
},
61+
onComplete: (index, key) {
62+
log('onComplete: $index, $key');
63+
if (index == 4) {
64+
SystemChrome.setSystemUIOverlayStyle(
65+
SystemUiOverlayStyle.light.copyWith(
66+
statusBarIconBrightness: Brightness.dark,
67+
statusBarColor: Colors.white,
68+
),
69+
);
70+
}
71+
},
72+
blurValue: 1,
73+
autoPlayDelay: const Duration(seconds: 3),
74+
builder: (context) => const MailPage(),
75+
globalTooltipActionConfig: const TooltipActionConfig(
76+
position: TooltipActionPosition.inside,
77+
alignment: MainAxisAlignment.spaceBetween,
78+
actionGap: 20,
79+
),
80+
globalTooltipActions: [
81+
// Here we don't need previous action for the first showcase widget
82+
// so we hide this action for the first showcase widget
83+
TooltipActionButton(
84+
type: TooltipDefaultActionType.previous,
85+
textStyle: const TextStyle(
4386
color: Colors.white,
44-
fontSize: 15,
4587
),
88+
hideActionWidgetForShowcase: [_firstShowcaseWidget],
4689
),
47-
),
48-
),
49-
),
50-
onStart: (index, key) {
51-
log('onStart: $index, $key');
52-
},
53-
onComplete: (index, key) {
54-
log('onComplete: $index, $key');
55-
if (index == 4) {
56-
SystemChrome.setSystemUIOverlayStyle(
57-
SystemUiOverlayStyle.light.copyWith(
58-
statusBarIconBrightness: Brightness.dark,
59-
statusBarColor: Colors.white,
90+
// Here we don't need next action for the last showcase widget so we
91+
// hide this action for the last showcase widget
92+
TooltipActionButton(
93+
type: TooltipDefaultActionType.next,
94+
textStyle: const TextStyle(
95+
color: Colors.white,
96+
),
97+
hideActionWidgetForShowcase: [_lastShowcaseWidget],
6098
),
61-
);
62-
}
63-
},
64-
blurValue: 1,
65-
autoPlayDelay: const Duration(seconds: 3),
66-
builder: (context) => const MailPage(),
67-
globalTooltipActionConfig: const TooltipActionConfig(
68-
position: TooltipActionPosition.inside,
69-
alignment: MainAxisAlignment.spaceBetween,
70-
actionGap: 20,
71-
),
72-
globalTooltipActions: [
73-
// Here we don't need previous action for the first showcase widget
74-
// so we hide this action for the first showcase widget
75-
TooltipActionButton(
76-
type: TooltipDefaultActionType.previous,
77-
textStyle: const TextStyle(
78-
color: Colors.white,
79-
),
80-
hideActionWidgetForShowcase: [_firstShowcaseWidget],
81-
),
82-
// Here we don't need next action for the last showcase widget so we
83-
// hide this action for the last showcase widget
84-
TooltipActionButton(
85-
type: TooltipDefaultActionType.next,
86-
textStyle: const TextStyle(
87-
color: Colors.white,
88-
),
89-
hideActionWidgetForShowcase: [_lastShowcaseWidget],
99+
],
100+
onDismiss: (key) {
101+
debugPrint('Dismissed at $key');
102+
},
90103
),
91-
],
92-
onDismiss: (key) {
93-
debugPrint('Dismissed at $key');
94-
},
104+
),
95105
),
96106
),
97107
);
@@ -118,8 +128,11 @@ class _MailPageState extends State<MailPage> {
118128
super.initState();
119129
//Start showcase view after current widget frames are drawn.
120130
WidgetsBinding.instance.addPostFrameCallback(
121-
(_) => ShowCaseWidget.of(context).startShowCase(
122-
[_firstShowcaseWidget, _two, _three, _four, _lastShowcaseWidget]),
131+
(_) async {
132+
await Future.delayed(Duration(seconds: 5));
133+
ShowCaseWidget.of(context).startShowCase(
134+
[_firstShowcaseWidget, _two, _three, _four, _lastShowcaseWidget]);
135+
},
123136
);
124137
mails = [
125138
Mail(
@@ -373,7 +386,7 @@ class _MailPageState extends State<MailPage> {
373386
controller: scrollController,
374387
physics: const BouncingScrollPhysics(),
375388
itemBuilder: (context, index) {
376-
if (index == 0) {
389+
if (index == 4) {
377390
return showcaseMailTile(_three, true, context, mails.first);
378391
}
379392
return MailTile(
@@ -386,7 +399,7 @@ class _MailPageState extends State<MailPage> {
386399
),
387400
),
388401
floatingActionButton: Showcase(
389-
key: _lastShowcaseWidget,
402+
key: _firstShowcaseWidget,
390403
title: 'Compose Mail',
391404
description: 'Click here to compose mail',
392405
targetBorderRadius: const BorderRadius.all(Radius.circular(16)),

lib/src/constants.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class Constants {
3434
borderRadius: BorderRadius.all(Radius.circular(8)),
3535
);
3636

37-
static const Widget defaultProgressIndicator = CircularProgressIndicator(
38-
valueColor: AlwaysStoppedAnimation(Colors.white),
37+
static const Widget defaultProgressIndicator =
38+
CircularProgressIndicator.adaptive(
39+
backgroundColor: Colors.white,
3940
);
4041

4142
static const Duration defaultAnimationDuration = Duration(milliseconds: 2000);

lib/src/enum.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ enum TooltipDefaultActionType {
9494
void onTap(ShowCaseWidgetState showCaseState) {
9595
switch (this) {
9696
case TooltipDefaultActionType.next:
97-
showCaseState.next(fromAutoPlayOrAction: true);
97+
showCaseState.next(forceNext: true);
9898
break;
9999
case TooltipDefaultActionType.previous:
100100
showCaseState.previous();

lib/src/get_position.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import 'package:flutter/material.dart';
2626

2727
class GetPosition {
2828
GetPosition({
29-
required this.context,
29+
required this.renderBox,
3030
required this.screenWidth,
3131
required this.screenHeight,
3232
this.padding = EdgeInsets.zero,
@@ -35,7 +35,7 @@ class GetPosition {
3535
_getRenderBox();
3636
}
3737

38-
final BuildContext context;
38+
final RenderBox? renderBox;
3939
final EdgeInsets padding;
4040
final double screenWidth;
4141
final double screenHeight;
@@ -47,7 +47,6 @@ class GetPosition {
4747
RenderBox? get box => _box;
4848

4949
void _getRenderBox() {
50-
final renderBox = context.findRenderObject() as RenderBox?;
5150
if (renderBox == null) return;
5251

5352
_box = renderBox;
@@ -136,5 +135,5 @@ class GetPosition {
136135
);
137136
}
138137

139-
Offset getOffSet() => _box?.size.center(topLeft()) ?? Offset.zero;
138+
Offset getOffset() => _box?.size.center(topLeft()) ?? Offset.zero;
140139
}

lib/src/layout_overlays.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ class OverlayBuilder extends StatefulWidget {
4141
super.key,
4242
required this.child,
4343
required this.updateOverlay,
44-
this.showOverlay = false,
4544
this.overlayBuilder,
4645
});
4746

48-
final bool showOverlay;
4947
final WidgetBuilder? overlayBuilder;
5048
final Widget child;
51-
final ValueSetter<VoidCallback> updateOverlay;
49+
final ValueSetter<ValueSetter<bool>> updateOverlay;
5250

5351
@override
5452
State<OverlayBuilder> createState() => _OverlayBuilderState();
@@ -57,27 +55,28 @@ class OverlayBuilder extends StatefulWidget {
5755
class _OverlayBuilderState extends State<OverlayBuilder> {
5856
OverlayEntry? _overlayEntry;
5957

58+
bool _showOverlay = false;
59+
6060
@override
6161
void initState() {
6262
super.initState();
6363

64-
if (widget.showOverlay) {
64+
if (_showOverlay) {
6565
WidgetsBinding.instance.addPostFrameCallback((_) => showOverlay());
6666
}
6767
widget.updateOverlay.call(_updateOverlay);
6868
}
6969

70-
void _updateOverlay() {
70+
void _updateOverlay(bool showOverlay) {
71+
_showOverlay = showOverlay;
7172
buildOverlay();
7273
WidgetsBinding.instance.addPostFrameCallback((_) => syncWidgetAndOverlay());
7374
}
7475

7576
@override
7677
void didUpdateWidget(OverlayBuilder oldWidget) {
7778
super.didUpdateWidget(oldWidget);
78-
if (oldWidget.showOverlay != widget.showOverlay && widget.showOverlay) {
79-
WidgetsBinding.instance.addPostFrameCallback((_) => showOverlay());
80-
}
79+
WidgetsBinding.instance.addPostFrameCallback((_) => showOverlay());
8180
}
8281

8382
@override
@@ -129,9 +128,9 @@ class _OverlayBuilderState extends State<OverlayBuilder> {
129128
}
130129

131130
void syncWidgetAndOverlay() {
132-
if (isShowingOverlay() && !widget.showOverlay) {
131+
if (isShowingOverlay() && !_showOverlay) {
133132
hideOverlay();
134-
} else if (!isShowingOverlay() && widget.showOverlay) {
133+
} else if (!isShowingOverlay() && _showOverlay) {
135134
showOverlay();
136135
}
137136
}

0 commit comments

Comments
 (0)