Skip to content

Commit a251c87

Browse files
Gold872BirjuVachhani
authored andcommitted
Add parameters for supported devices
1 parent 8f249d0 commit a251c87

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packages/flutter_box_transform/lib/src/handle_builders.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:ui';
2+
13
import 'package:box_transform/box_transform.dart';
24
import 'package:flutter/foundation.dart';
35
import 'package:flutter/material.dart';
@@ -17,6 +19,9 @@ class CornerHandleWidget extends StatelessWidget {
1719
/// The size of the handle's gesture response area.
1820
final double handleTapSize;
1921

22+
/// The kind of devices that are allowed to be recognized.
23+
final Set<PointerDeviceKind> supportedDevices;
24+
2025
/// Called when the handle dragging starts.
2126
final GestureDragStartCallback? onPanStart;
2227

@@ -43,6 +48,7 @@ class CornerHandleWidget extends StatelessWidget {
4348
super.key,
4449
required this.handlePosition,
4550
required this.handleTapSize,
51+
required this.supportedDevices,
4652
required this.builder,
4753
this.onPanStart,
4854
this.onPanUpdate,
@@ -61,6 +67,7 @@ class CornerHandleWidget extends StatelessWidget {
6167
if (enabled) {
6268
child = GestureDetector(
6369
behavior: HitTestBehavior.opaque,
70+
supportedDevices: supportedDevices,
6471
onPanStart: onPanStart,
6572
onPanUpdate: onPanUpdate,
6673
onPanEnd: onPanEnd,
@@ -118,6 +125,9 @@ class SideHandleWidget extends StatelessWidget {
118125
/// The thickness of the handle that is used for gesture detection.
119126
final double handleTapSize;
120127

128+
/// The kind of devices that are allowed to be recognized.
129+
final Set<PointerDeviceKind> supportedDevices;
130+
121131
/// Called when the handle dragging starts.
122132
final GestureDragStartCallback? onPanStart;
123133

@@ -144,6 +154,7 @@ class SideHandleWidget extends StatelessWidget {
144154
super.key,
145155
required this.handlePosition,
146156
required this.handleTapSize,
157+
required this.supportedDevices,
147158
required this.builder,
148159
this.onPanStart,
149160
this.onPanUpdate,
@@ -162,6 +173,7 @@ class SideHandleWidget extends StatelessWidget {
162173
if (enabled) {
163174
child = GestureDetector(
164175
behavior: HitTestBehavior.opaque,
176+
supportedDevices: supportedDevices,
165177
onPanStart: onPanStart,
166178
onPanUpdate: onPanUpdate,
167179
onPanEnd: onPanEnd,

packages/flutter_box_transform/lib/src/transformable_box.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/gestures.dart';
12
import 'package:flutter/material.dart';
23

34
import '../flutter_box_transform.dart';
@@ -66,6 +67,16 @@ class TransformableBox extends StatefulWidget {
6667
/// visible, it will not be shown and will not be interactive.
6768
final Set<HandlePosition> visibleHandles;
6869

70+
/// The kind of devices that are allowed to be recognized for drag events.
71+
///
72+
/// By default, events from all device types will be recognized for drag events.
73+
final Set<PointerDeviceKind> supportedDragDevices;
74+
75+
/// The kind of devices that are allowed to be recognized for resize events.
76+
///
77+
/// By default, events from all device types will be recognized for resize events.
78+
final Set<PointerDeviceKind> supportedResizeDevices;
79+
6980
/// The initial box that will be used to position set the initial size of
7081
/// the [TransformableBox] widget.
7182
///
@@ -231,6 +242,8 @@ class TransformableBox extends StatefulWidget {
231242
this.handleAlignment = HandleAlignment.center,
232243
this.enabledHandles = const {...HandlePosition.values},
233244
this.visibleHandles = const {...HandlePosition.values},
245+
this.supportedDragDevices = const {...PointerDeviceKind.values},
246+
this.supportedResizeDevices = const {...PointerDeviceKind.values},
234247

235248
// Raw values.
236249
Rect? rect,
@@ -576,6 +589,7 @@ class _TransformableBoxState extends State<TransformableBox> {
576589
if (widget.draggable) {
577590
content = GestureDetector(
578591
behavior: HitTestBehavior.translucent,
592+
supportedDevices: widget.supportedDragDevices,
579593
onTap: onTap,
580594
onPanStart: onDragPanStart,
581595
onPanUpdate: onDragPanUpdate,
@@ -606,6 +620,7 @@ class _TransformableBoxState extends State<TransformableBox> {
606620
key: ValueKey(handle),
607621
handlePosition: handle,
608622
handleTapSize: widget.handleTapSize,
623+
supportedDevices: widget.supportedResizeDevices,
609624
enabled: widget.enabledHandles.contains(handle),
610625
visible: widget.visibleHandles.contains(handle),
611626
onPanStart: (event) => onHandlePanStart(event, handle),
@@ -622,6 +637,7 @@ class _TransformableBoxState extends State<TransformableBox> {
622637
key: ValueKey(handle),
623638
handlePosition: handle,
624639
handleTapSize: widget.handleTapSize,
640+
supportedDevices: widget.supportedResizeDevices,
625641
enabled: widget.enabledHandles.contains(handle),
626642
visible: widget.visibleHandles.contains(handle),
627643
onPanStart: (event) => onHandlePanStart(event, handle),

0 commit comments

Comments
 (0)