Skip to content

Commit 2e0e943

Browse files
joakimungeBirjuVachhani
authored andcommitted
feat: add onTap event and handler to TransformableBox
1 parent c303e57 commit 2e0e943

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/flutter_box_transform/lib/src/transformable_box.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class TransformableBox extends StatefulWidget {
142142
/// or the flip.
143143
final RectChangeEvent? onChanged;
144144

145+
/// A callback that is called every time the [TransformableBox] is tapped.
146+
final TapEvent? onTap;
147+
145148
/// A callback that is called when [TransformableBox] triggers a pointer down
146149
/// event to begin a drag operation.
147150
final RectDragStartEvent? onDragStart;
@@ -247,6 +250,9 @@ class TransformableBox extends StatefulWidget {
247250
this.draggable = true,
248251
this.allowFlippingWhileResizing = true,
249252

253+
// Tap events
254+
this.onTap,
255+
250256
// Either resize or drag triggers.
251257
this.onChanged,
252258

@@ -489,6 +495,9 @@ class _TransformableBoxState extends State<TransformableBox> {
489495
widget.onTerminalSizeReached?.call(false, false, false, false);
490496
}
491497

498+
/// Called when the box is tapped.
499+
void onTap() => widget.onTap?.call();
500+
492501
/// Called when the box drag event starts.
493502
void onDragPanStart(DragStartDetails event) {
494503
// Two fingers were used to start the drag. This produces issues with
@@ -545,6 +554,7 @@ class _TransformableBoxState extends State<TransformableBox> {
545554
if (widget.draggable) {
546555
content = GestureDetector(
547556
behavior: HitTestBehavior.translucent,
557+
onTap: onTap,
548558
onPanStart: onDragPanStart,
549559
onPanUpdate: onDragPanUpdate,
550560
onPanEnd: onDragPanEnd,

packages/flutter_box_transform/lib/src/typedefs.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ typedef RectChangeEvent = void Function(
2525
DragUpdateDetails event,
2626
);
2727

28+
/// A callback that is called when the box is tapped.
29+
typedef TapEvent = void Function();
30+
2831
/// A callback that is called when the box begins a drag operation.
2932
typedef RectDragStartEvent = void Function(
3033
DragStartDetails event,

0 commit comments

Comments
 (0)