Skip to content

Commit

Permalink
feat: add onTap event and handler to TransformableBox
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimunge committed Jun 4, 2024
1 parent c303e57 commit a5fefc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/flutter_box_transform/lib/src/transformable_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class TransformableBox extends StatefulWidget {
/// or the flip.
final RectChangeEvent? onChanged;

/// A callback that is called every time the [TransformableBox] is tapped.
final TapEvent? onTap;

/// A callback that is called when [TransformableBox] triggers a pointer down
/// event to begin a drag operation.
final RectDragStartEvent? onDragStart;
Expand Down Expand Up @@ -247,6 +250,9 @@ class TransformableBox extends StatefulWidget {
this.draggable = true,
this.allowFlippingWhileResizing = true,

// Tap events
this.onTap,

// Either resize or drag triggers.
this.onChanged,

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

/// Called when the box is tapped.
void onTap() => widget.onTap?.call();

/// Called when the box drag event starts.
void onDragPanStart(DragStartDetails event) {
// Two fingers were used to start the drag. This produces issues with
Expand Down Expand Up @@ -545,6 +554,7 @@ class _TransformableBoxState extends State<TransformableBox> {
if (widget.draggable) {
content = GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: onTap,
onPanStart: onDragPanStart,
onPanUpdate: onDragPanUpdate,
onPanEnd: onDragPanEnd,
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter_box_transform/lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ typedef RectChangeEvent = void Function(
DragUpdateDetails event,
);

/// A callback that is called when the box is tapped.
typedef TapEvent = void Function();

/// A callback that is called when the box begins a drag operation.
typedef RectDragStartEvent = void Function(
DragStartDetails event,
Expand Down

0 comments on commit a5fefc8

Please sign in to comment.