Skip to content

Commit

Permalink
fix: 🐛 Fixed target hit area (#409)
Browse files Browse the repository at this point in the history
- Updated `IgnorePointer` to `AbsorbPointer` as ignore pointer is not blocking tap to descendants
- removed `FractionalTranslation` as it is not shifting tappable area and only shifting paint of widgets
- Made `size` and `shapeBorder` not nullable as we are assigning not null values to that constructor variable
- Updated default `offset` to `rectBound.topLeft` as to switch from positioning the target widget overlay over center of the target widget to topLeft and dismissing need of `FractionalTranslation`.
  • Loading branch information
Sahil-Simform authored Mar 7, 2024
1 parent 66af50f commit 3623642
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions lib/src/showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class _ShowcaseState extends State<Showcase> {
if (_isScrollRunning) Center(child: widget.scrollLoadingWidget),
if (!_isScrollRunning) ...[
_TargetWidget(
offset: offset,
offset: rectBound.topLeft,
size: size,
onTap: _getOnTargetTap,
radius: widget.targetBorderRadius,
Expand Down Expand Up @@ -626,20 +626,20 @@ class _ShowcaseState extends State<Showcase> {

class _TargetWidget extends StatelessWidget {
final Offset offset;
final Size? size;
final Size size;
final VoidCallback? onTap;
final VoidCallback? onDoubleTap;
final VoidCallback? onLongPress;
final ShapeBorder? shapeBorder;
final ShapeBorder shapeBorder;
final BorderRadius? radius;
final bool disableDefaultChildGestures;

const _TargetWidget({
Key? key,
required this.offset,
this.size,
required this.size,
required this.shapeBorder,
this.onTap,
this.shapeBorder,
this.radius,
this.onDoubleTap,
this.onLongPress,
Expand All @@ -649,34 +649,31 @@ class _TargetWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Positioned(
//TODO: Add target padding in major version upgrade
top: offset.dy,
left: offset.dx,
child: disableDefaultChildGestures
? IgnorePointer(
? AbsorbPointer(
child: targetWidgetContent(),
)
: targetWidgetContent(),
);
}

Widget targetWidgetContent() {
return FractionalTranslation(
translation: const Offset(-0.5, -0.5),
child: GestureDetector(
onTap: onTap,
onLongPress: onLongPress,
onDoubleTap: onDoubleTap,
child: Container(
height: size!.height + 16,
width: size!.width + 16,
decoration: ShapeDecoration(
shape: radius != null
? RoundedRectangleBorder(borderRadius: radius!)
: shapeBorder ??
const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
),
return GestureDetector(
onTap: onTap,
onLongPress: onLongPress,
onDoubleTap: onDoubleTap,
child: Container(
//TODO: Add target padding in major version upgrade and
// remove default 16 padding from this widget
height: size.height + 16,
width: size.width + 16,
decoration: ShapeDecoration(
shape: radius != null
? RoundedRectangleBorder(borderRadius: radius!)
: shapeBorder,
),
),
);
Expand Down

0 comments on commit 3623642

Please sign in to comment.