Skip to content

Commit 43c03f7

Browse files
Sahil-Simformaditya-css
authored andcommitted
fix: 🐛 Fix clipper and documentation issues
1 parent 4bb6360 commit 43c03f7

12 files changed

+116
-110
lines changed

example/lib/main.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class _MailPageState extends State<MailPage> {
120120
//Start showcase view after current widget frames are drawn.
121121
WidgetsBinding.instance.addPostFrameCallback(
122122
(_) => ShowcaseView.get().startShowCase(
123-
[_firstShowcaseWidget, _two, _three, _four, _lastShowcaseWidget]),
123+
[_firstShowcaseWidget, _two, _three, _four, _lastShowcaseWidget],
124+
),
124125
);
125126
mails = [
126127
Mail(
@@ -192,6 +193,8 @@ class _MailPageState extends State<MailPage> {
192193
@override
193194
void dispose() {
194195
scrollController.dispose();
196+
// Unregister the showcase view when the widget is disposed
197+
ShowcaseView.get().unregister();
195198
super.dispose();
196199
}
197200

lib/src/models/tooltip_action_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
import 'package:flutter/material.dart';
2323

24-
import '../../showcaseview.dart';
24+
import '../utils/enum.dart';
2525

2626
class TooltipActionConfig {
2727
/// Configuration options for tooltip action buttons.

lib/src/showcase/showcase.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import 'package:flutter/material.dart';
2525
import '../models/showcase_scope.dart';
2626
import '../models/tooltip_action_button.dart';
2727
import '../models/tooltip_action_config.dart';
28-
import '../showcase_widget.dart';
2928
import '../utils/constants.dart';
3029
import '../utils/enum.dart';
3130
import '../utils/overlay_manager.dart';
@@ -251,7 +250,7 @@ class Showcase extends StatefulWidget {
251250
/// A key that is unique across the entire app.
252251
///
253252
/// This Key will be used to control state of individual showcase and also
254-
/// used in [ShowcaseView.startShowcase] to define position of current
253+
/// used in [ShowcaseView.setupShowcase] to define position of current
255254
/// target widget while showcasing.
256255
final GlobalKey showcaseKey;
257256

lib/src/showcase/showcase_controller.dart

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ShowcaseController {
119119
/// tree.
120120
bool get _mounted => getState().mounted;
121121

122-
/// Callback to start the showcase.
122+
/// Callback to setup the showcase.
123123
///
124124
/// Initializes the showcase by calculating positions and preparing visual
125125
/// elements.
@@ -134,7 +134,7 @@ class ShowcaseController {
134134
///
135135
/// This method is typically called internally by the showcase system but
136136
/// can also be called manually to force a recalculation of showcase elements.
137-
void startShowcase({bool shouldUpdateOverlay = true}) {
137+
void setupShowcase({bool shouldUpdateOverlay = true}) {
138138
if (!showcaseView.enableShowcase || !_mounted) return;
139139

140140
recalculateRootWidgetSize(
@@ -144,13 +144,6 @@ class ShowcaseController {
144144
globalFloatingActionWidget = showcaseView
145145
.getFloatingActionWidget(config.showcaseKey)
146146
?.call(_context);
147-
// final size = rootWidgetSize ?? MediaQuery.sizeOf(_context);
148-
// position ??= TargetPositionService(
149-
// rootRenderObject: rootRenderObject,
150-
// screenSize: size,
151-
// renderBox: _context.findRenderObject() as RenderBox?,
152-
// padding: config.targetPadding,
153-
// );
154147
}
155148

156149
/// Used to scroll the target into view.
@@ -175,25 +168,15 @@ class ShowcaseController {
175168
}
176169

177170
isScrollRunning = true;
178-
// updateControllerData();
179-
startShowcase(shouldUpdateOverlay: shouldUpdateOverlay);
180-
// OverlayManager.instance.update(
181-
// show: showcaseView.isShowcaseRunning,
182-
// scope: showcaseView.scope,
183-
// );
171+
setupShowcase(shouldUpdateOverlay: shouldUpdateOverlay);
184172
await Scrollable.ensureVisible(
185173
_context,
186174
duration: showcaseView.scrollDuration,
187175
alignment: config.scrollAlignment,
188176
);
189177

190178
isScrollRunning = false;
191-
// updateControllerData();
192-
startShowcase(shouldUpdateOverlay: shouldUpdateOverlay);
193-
// OverlayManager.instance.update(
194-
// show: showcaseView.isShowcaseRunning,
195-
// scope: showcaseView.scope,
196-
// );
179+
setupShowcase(shouldUpdateOverlay: shouldUpdateOverlay);
197180
}
198181

199182
/// Handles tap on barrier area.
@@ -231,8 +214,6 @@ class ShowcaseController {
231214

232215
_initRootWidget();
233216

234-
updateControllerData();
235-
236217
if (shouldUpdateOverlay) {
237218
OverlayManager.instance.update(
238219
show: showcaseView.isShowcaseRunning,

lib/src/showcase/showcase_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
*/
2222
import 'package:flutter/widgets.dart';
2323

24-
import '../../showcaseview.dart';
2524
import '../models/showcase_scope.dart';
2625
import '../utils/constants.dart';
2726
import '../utils/extensions.dart';
2827
import 'showcase_controller.dart';
28+
import 'showcase_view.dart';
2929

3030
/// A scoped service locator for showcase functionality.
3131
///

lib/src/showcase/showcase_view.dart

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ class ShowcaseView {
6262
/// options like auto-play, animation, and many more.
6363
ShowcaseView.register({
6464
this.scope = Constants.defaultScope,
65-
this.onFinish,
6665
this.onStart,
66+
this.onFinish,
6767
this.onComplete,
6868
this.onDismiss,
69+
this.enableShowcase = true,
6970
this.autoPlay = false,
7071
this.autoPlayDelay = Constants.defaultAutoPlayDelay,
7172
this.enableAutoPlayLock = false,
72-
this.blurValue = 0,
73-
this.scrollDuration = Constants.defaultScrollDuration,
74-
this.disableMovingAnimation = false,
75-
this.disableScaleAnimation = false,
7673
this.enableAutoScroll = false,
74+
this.scrollDuration = Constants.defaultScrollDuration,
7775
this.disableBarrierInteraction = false,
78-
this.enableShowcase = true,
76+
this.disableScaleAnimation = false,
77+
this.disableMovingAnimation = false,
78+
this.blurValue = 0,
7979
this.globalTooltipActionConfig,
8080
this.globalTooltipActions,
8181
this.globalFloatingActionWidget,
@@ -263,10 +263,6 @@ class ShowcaseView {
263263
if (!_mounted) return;
264264

265265
_cleanupAfterSteps();
266-
OverlayManager.instance.update(
267-
show: isShowcaseRunning,
268-
scope: scope,
269-
);
270266
}
271267

272268
/// Cleans up resources when unregistering the showcase view.
@@ -321,7 +317,7 @@ class ShowcaseView {
321317
_ids = widgetIds;
322318
_activeWidgetId = 0;
323319
_onStart();
324-
// OverlayManager.instance.update(show: isShowcaseRunning, scope: scope);
320+
OverlayManager.instance.update(show: isShowcaseRunning, scope: scope);
325321
} else {
326322
Future.delayed(delay, () => _startShowcase(Duration.zero, widgetIds));
327323
}
@@ -344,12 +340,13 @@ class ShowcaseView {
344340
(_) {
345341
if (!_mounted) return;
346342
_activeWidgetId = id;
347-
_onStart();
343+
348344
if (_activeWidgetId! >= _ids!.length) {
349345
_cleanupAfterSteps();
350346
onFinish?.call();
347+
} else {
348+
_onStart();
351349
}
352-
OverlayManager.instance.update(show: isShowcaseRunning, scope: scope);
353350
},
354351
);
355352
}
@@ -418,7 +415,7 @@ class ShowcaseView {
418415
await firstController?.scrollIntoView();
419416
} else {
420417
for (var i = 0; i < controllerLength; i++) {
421-
controllers[i].startShowcase(shouldUpdateOverlay: i == 0);
418+
controllers[i].setupShowcase(shouldUpdateOverlay: i == 0);
422419
}
423420
}
424421
}
@@ -468,6 +465,7 @@ class ShowcaseView {
468465
void _cleanupAfterSteps() {
469466
_ids = _activeWidgetId = null;
470467
_cancelTimer();
468+
OverlayManager.instance.update(show: isShowcaseRunning, scope: scope);
471469
}
472470

473471
@override

lib/src/tooltip/render_position_delegate.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -162,48 +162,10 @@ class _RenderPositionDelegate extends RenderBox
162162
// Final layout and positioning
163163
_performFinalChildLayout();
164164

165-
// _calculateAndSetFinalSize();
166-
167165
// Cleanup
168166
RenderObjectManager.clear();
169167
}
170168

171-
/// Calculate and set the final size of the render object based on the bounds of its children
172-
void _calculateAndSetFinalSize() {
173-
// Start with an empty Rect to track the bounds
174-
Rect bounds = Rect.zero;
175-
bool firstChild = true;
176-
177-
// Iterate through all children to calculate the bounding box
178-
var child = this.firstChild;
179-
while (child != null) {
180-
final childParentData = child.parentData! as MultiChildLayoutParentData;
181-
final childRect = Rect.fromPoints(
182-
childParentData.offset + Offset(child.size.width, child.size.height),
183-
childParentData.offset + Offset(child.size.width, child.size.height),
184-
);
185-
186-
// For the first child, initialize bounds; for others, expand it
187-
if (firstChild) {
188-
bounds = childRect;
189-
firstChild = false;
190-
} else {
191-
bounds = bounds.expandToInclude(childRect);
192-
}
193-
194-
child = childParentData.nextSibling;
195-
}
196-
197-
// Add a small padding to ensure we don't clip any content
198-
bounds = bounds.inflate(2.0);
199-
200-
// Constrain the size to the available constraints
201-
final constrainedSize = constraints.constrain(bounds.size);
202-
203-
// Set the size of this render object to the calculated bounds
204-
size = constrainedSize;
205-
}
206-
207169
/// Initialize layout variables and set size
208170
void _initializeLayout() {
209171
// Set size for this render object

lib/src/tooltip/tooltip_widget.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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.copyWith(left: 0, right: 0),
187187
decoration: BoxDecoration(
188188
color: widget.tooltipBackgroundColor,
189189
borderRadius: widget.tooltipBorderRadius ??
@@ -195,8 +195,9 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
195195
if (widget.title case final title?)
196196
DefaultTooltipTextWidget(
197197
padding: (widget.titlePadding ?? EdgeInsets.zero).add(
198-
EdgeInsets.symmetric(
199-
horizontal: widget.tooltipPadding?.horizontal ?? 0,
198+
EdgeInsets.only(
199+
left: widget.tooltipPadding.left,
200+
right: widget.tooltipPadding.right,
200201
),
201202
),
202203
text: title,
@@ -214,8 +215,8 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
214215
padding:
215216
(widget.descriptionPadding ?? EdgeInsets.zero).add(
216217
EdgeInsets.only(
217-
left: widget.tooltipPadding?.left ?? 0,
218-
right: widget.tooltipPadding?.right ?? 0,
218+
left: widget.tooltipPadding.left,
219+
right: widget.tooltipPadding.right,
219220
),
220221
),
221222
text: desc,
@@ -233,8 +234,8 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
233234
ActionWidget(
234235
tooltipActionConfig: widget.tooltipActionConfig,
235236
outsidePadding: EdgeInsets.only(
236-
left: widget.tooltipPadding?.left ?? 0,
237-
right: widget.tooltipPadding?.right ?? 0,
237+
left: widget.tooltipPadding.left,
238+
right: widget.tooltipPadding.right,
238239
),
239240
alignment: widget.tooltipActionConfig.alignment,
240241
crossAxisAlignment:
@@ -295,8 +296,9 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
295296
_TooltipLayoutId(
296297
id: TooltipLayoutSlot.arrow,
297298
child: CustomPaint(
298-
painter:
299-
_ArrowPainter(strokeColor: widget.tooltipBackgroundColor!),
299+
painter: _ArrowPainter(
300+
strokeColor: widget.tooltipBackgroundColor,
301+
),
300302
size: const Size(Constants.arrowWidth, Constants.arrowHeight),
301303
),
302304
),

lib/src/utils/overlay_manager.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import 'dart:ui';
2424

2525
import 'package:flutter/material.dart';
2626

27-
import '../../showcaseview.dart';
2827
import '../models/linked_showcase_data_model.dart';
28+
import '../showcase/showcase.dart';
2929
import '../showcase/showcase_controller.dart';
3030
import '../showcase/showcase_service.dart';
31+
import '../showcase/showcase_view.dart';
3132
import 'extensions.dart';
3233
import 'shape_clipper.dart';
3334

0 commit comments

Comments
 (0)