Skip to content

Commit b64efc7

Browse files
committed
test: 🧪 Added test cases
1 parent 43c03f7 commit b64efc7

File tree

12 files changed

+7611
-29
lines changed

12 files changed

+7611
-29
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Flutter Tests
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
test:
8+
name: Run Tests
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Install Flutter
14+
uses: subosito/flutter-action@v2
15+
with:
16+
flutter-version: '3.10.0'
17+
cache: true
18+
cache-key: 'flutter-macos-stable-3.10.0-apple'
19+
cache-path: '${{ runner.tool_cache }}/flutter/macos-stable-3.10.0-apple'
20+
pub-cache-key: 'flutter-pub-macos-stable-3.10.0-apple'
21+
22+
- name: Get dependencies
23+
run: flutter pub get
24+
25+
- name: Analyze project
26+
run: flutter analyze
27+
28+
- name: Run tests
29+
run: flutter test --coverage
30+
31+
- name: Upload coverage reports to Codecov
32+
uses: codecov/codecov-action@v3
33+
with:
34+
file: ./coverage/lcov.info
35+
fail_ci_if_error: false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# ShowCaseView
55

6-
[![Build](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/actions/workflows/flutter.yaml/badge.svg?branch=master)](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/actions) [![showcaseview](https://img.shields.io/pub/v/showcaseview?label=showcaseview)](https://pub.dev/packages/showcaseview)
6+
[![showcaseview](https://img.shields.io/pub/v/showcaseview?label=showcaseview)](https://pub.dev/packages/showcaseview) [![Build](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/actions/workflows/flutter.yaml/badge.svg?branch=master)](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/actions) [![Tests](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/actions/workflows/flutter_tests.yaml/badge.svg?branch=master)](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/actions)
77

88
A Flutter package allows you to Showcase/Highlight your widgets.
99

lib/src/showcase/showcase_view.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,16 @@ class ShowcaseView {
339339
_onComplete().then(
340340
(_) {
341341
if (!_mounted) return;
342+
// Update active widget ID before starting the next showcase
342343
_activeWidgetId = id;
343344

344345
if (_activeWidgetId! >= _ids!.length) {
345346
_cleanupAfterSteps();
346347
onFinish?.call();
347348
} else {
348-
_onStart();
349+
// Add a short delay before starting the next showcase to ensure proper state update
350+
// Then start the new showcase
351+
Future.microtask(_onStart);
349352
}
350353
},
351354
);
@@ -402,6 +405,7 @@ class ShowcaseView {
402405
Future<void> _onStart() async {
403406
_activeWidgetId ??= 0;
404407
if (_activeWidgetId! < _ids!.length) {
408+
// Call onStart callback with current index and key
405409
onStart?.call(_activeWidgetId, _ids![_activeWidgetId!]);
406410
final controllers = _getCurrentActiveControllers;
407411
final controllerLength = controllers.length;
@@ -414,18 +418,27 @@ class ShowcaseView {
414418
if (controllerLength == 1 && isAutoScroll) {
415419
await firstController?.scrollIntoView();
416420
} else {
421+
// Setup showcases after data is updated
417422
for (var i = 0; i < controllerLength; i++) {
418423
controllers[i].setupShowcase(shouldUpdateOverlay: i == 0);
419424
}
425+
426+
// Make sure the overlay is updated to reflect new properties
427+
OverlayManager.instance.update(show: isShowcaseRunning, scope: scope);
420428
}
421429
}
422430

431+
// Cancel any existing timer before setting up a new one
432+
423433
if (autoPlay) {
424434
_cancelTimer();
425-
// Showcase is first.
435+
// Get the config from the current showcase if available
426436
final config = _getCurrentActiveControllers.firstOrNull?.config;
437+
final effectiveDelay = config?.autoPlayDelay ?? autoPlayDelay;
438+
439+
// Create a new timer with the effective delay
427440
_timer = Timer(
428-
config?.autoPlayDelay ?? autoPlayDelay,
441+
effectiveDelay,
429442
() => next(force: true),
430443
);
431444
}

lib/src/tooltip/arrow_painter.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@
2121
*/
2222
part of 'tooltip.dart';
2323

24+
class ShowcaseArrow extends StatelessWidget {
25+
const ShowcaseArrow({
26+
super.key,
27+
required this.strokeColor,
28+
});
29+
30+
final Color strokeColor;
31+
32+
@override
33+
Widget build(BuildContext context) {
34+
return CustomPaint(
35+
painter: _ArrowPainter(
36+
strokeColor: strokeColor,
37+
),
38+
size: const Size(Constants.arrowWidth, Constants.arrowHeight),
39+
);
40+
}
41+
}
42+
2443
class _ArrowPainter extends CustomPainter {
2544
_ArrowPainter({
2645
this.strokeColor = Colors.black,

lib/src/tooltip/tooltip_widget.dart

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
173173
: SystemMouseCursors.click,
174174
child: GestureDetector(
175175
onTap: widget.onTooltipTap,
176-
child: Center(child: widget.container ?? const SizedBox.shrink()),
176+
child: widget.container ?? const SizedBox.shrink(),
177177
),
178178
)
179179
: MouseRegion(
@@ -183,7 +183,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
183183
child: GestureDetector(
184184
onTap: widget.onTooltipTap,
185185
child: Container(
186-
padding: widget.tooltipPadding.copyWith(left: 0, right: 0),
186+
padding: widget.tooltipPadding,
187187
decoration: BoxDecoration(
188188
color: widget.tooltipBackgroundColor,
189189
borderRadius: widget.tooltipBorderRadius ??
@@ -194,12 +194,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
194194
children: <Widget>[
195195
if (widget.title case final title?)
196196
DefaultTooltipTextWidget(
197-
padding: (widget.titlePadding ?? EdgeInsets.zero).add(
198-
EdgeInsets.only(
199-
left: widget.tooltipPadding.left,
200-
right: widget.tooltipPadding.right,
201-
),
202-
),
197+
padding: widget.titlePadding ?? EdgeInsets.zero,
203198
text: title,
204199
textAlign: widget.titleTextAlign,
205200
alignment: widget.titleAlignment,
@@ -212,13 +207,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
212207
),
213208
if (widget.description case final desc?)
214209
DefaultTooltipTextWidget(
215-
padding:
216-
(widget.descriptionPadding ?? EdgeInsets.zero).add(
217-
EdgeInsets.only(
218-
left: widget.tooltipPadding.left,
219-
right: widget.tooltipPadding.right,
220-
),
221-
),
210+
padding: widget.descriptionPadding ?? EdgeInsets.zero,
222211
text: desc,
223212
textAlign: widget.descriptionTextAlign,
224213
alignment: widget.descriptionAlignment,
@@ -233,10 +222,6 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
233222
widget.tooltipActionConfig.position.isInside)
234223
ActionWidget(
235224
tooltipActionConfig: widget.tooltipActionConfig,
236-
outsidePadding: EdgeInsets.only(
237-
left: widget.tooltipPadding.left,
238-
right: widget.tooltipPadding.right,
239-
),
240225
alignment: widget.tooltipActionConfig.alignment,
241226
crossAxisAlignment:
242227
widget.tooltipActionConfig.crossAxisAlignment,
@@ -295,11 +280,8 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
295280
if (widget.showArrow)
296281
_TooltipLayoutId(
297282
id: TooltipLayoutSlot.arrow,
298-
child: CustomPaint(
299-
painter: _ArrowPainter(
300-
strokeColor: widget.tooltipBackgroundColor,
301-
),
302-
size: const Size(Constants.arrowWidth, Constants.arrowHeight),
283+
child: ShowcaseArrow(
284+
strokeColor: widget.tooltipBackgroundColor,
303285
),
304286
),
305287
],

lib/src/utils/overlay_manager.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class OverlayManager {
7878
ShowcaseService.instance.updateCurrentScope(scope);
7979
}
8080
_shouldShow = show;
81-
_rebuild();
8281
_sync();
8382
}
8483

@@ -131,6 +130,8 @@ class OverlayManager {
131130
_hide();
132131
} else if (!_isShowing && _shouldShow) {
133132
_show(_getBuilder);
133+
} else {
134+
_rebuild();
134135
}
135136
}
136137

@@ -177,6 +178,10 @@ class OverlayManager {
177178
);
178179

179180
return Stack(
181+
// This key is used to force rebuild the overlay when needed.
182+
// this key enables `_overlayEntry?.markNeedsBuild();` to detect that
183+
// output of the builder has changed.
184+
key: ValueKey(firstShowcaseConfig.hashCode),
180185
children: [
181186
GestureDetector(
182187
onTap: firstController.handleBarrierTap,

0 commit comments

Comments
 (0)