From da75f1b233d8b07992f2929a11cc2413a95e0271 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:22:46 -0400 Subject: [PATCH] Add parameters for supported devices --- .../lib/src/handle_builders.dart | 12 ++++++++++++ .../lib/src/transformable_box.dart | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/flutter_box_transform/lib/src/handle_builders.dart b/packages/flutter_box_transform/lib/src/handle_builders.dart index 521ffae..d811450 100644 --- a/packages/flutter_box_transform/lib/src/handle_builders.dart +++ b/packages/flutter_box_transform/lib/src/handle_builders.dart @@ -1,3 +1,5 @@ +import 'dart:ui'; + import 'package:box_transform/box_transform.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -17,6 +19,9 @@ class CornerHandleWidget extends StatelessWidget { /// The size of the handle's gesture response area. final double handleTapSize; + /// The kind of devices that are allowed to be recognized. + final Set supportedDevices; + /// Called when the handle dragging starts. final GestureDragStartCallback? onPanStart; @@ -43,6 +48,7 @@ class CornerHandleWidget extends StatelessWidget { super.key, required this.handlePosition, required this.handleTapSize, + required this.supportedDevices, required this.builder, this.onPanStart, this.onPanUpdate, @@ -61,6 +67,7 @@ class CornerHandleWidget extends StatelessWidget { if (enabled) { child = GestureDetector( behavior: HitTestBehavior.opaque, + supportedDevices: supportedDevices, onPanStart: onPanStart, onPanUpdate: onPanUpdate, onPanEnd: onPanEnd, @@ -118,6 +125,9 @@ class SideHandleWidget extends StatelessWidget { /// The thickness of the handle that is used for gesture detection. final double handleTapSize; + /// The kind of devices that are allowed to be recognized. + final Set supportedDevices; + /// Called when the handle dragging starts. final GestureDragStartCallback? onPanStart; @@ -144,6 +154,7 @@ class SideHandleWidget extends StatelessWidget { super.key, required this.handlePosition, required this.handleTapSize, + required this.supportedDevices, required this.builder, this.onPanStart, this.onPanUpdate, @@ -162,6 +173,7 @@ class SideHandleWidget extends StatelessWidget { if (enabled) { child = GestureDetector( behavior: HitTestBehavior.opaque, + supportedDevices: supportedDevices, onPanStart: onPanStart, onPanUpdate: onPanUpdate, onPanEnd: onPanEnd, diff --git a/packages/flutter_box_transform/lib/src/transformable_box.dart b/packages/flutter_box_transform/lib/src/transformable_box.dart index e64fbda..dd46722 100644 --- a/packages/flutter_box_transform/lib/src/transformable_box.dart +++ b/packages/flutter_box_transform/lib/src/transformable_box.dart @@ -1,3 +1,4 @@ +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import '../flutter_box_transform.dart'; @@ -66,6 +67,16 @@ class TransformableBox extends StatefulWidget { /// visible, it will not be shown and will not be interactive. final Set visibleHandles; + /// The kind of devices that are allowed to be recognized for drag events. + /// + /// By default, events from all device types will be recognized for drag events. + final Set supportedDragDevices; + + /// The kind of devices that are allowed to be recognized for resize events. + /// + /// By default, events from all device types will be recognized for resize events. + final Set supportedResizeDevices; + /// The initial box that will be used to position set the initial size of /// the [TransformableBox] widget. /// @@ -231,6 +242,8 @@ class TransformableBox extends StatefulWidget { this.handleAlignment = HandleAlignment.center, this.enabledHandles = const {...HandlePosition.values}, this.visibleHandles = const {...HandlePosition.values}, + this.supportedDragDevices = const {...PointerDeviceKind.values}, + this.supportedResizeDevices = const {...PointerDeviceKind.values}, // Raw values. Rect? rect, @@ -576,6 +589,7 @@ class _TransformableBoxState extends State { if (widget.draggable) { content = GestureDetector( behavior: HitTestBehavior.translucent, + supportedDevices: widget.supportedDragDevices, onTap: onTap, onPanStart: onDragPanStart, onPanUpdate: onDragPanUpdate, @@ -606,6 +620,7 @@ class _TransformableBoxState extends State { key: ValueKey(handle), handlePosition: handle, handleTapSize: widget.handleTapSize, + supportedDevices: widget.supportedResizeDevices, enabled: widget.enabledHandles.contains(handle), visible: widget.visibleHandles.contains(handle), onPanStart: (event) => onHandlePanStart(event, handle), @@ -622,6 +637,7 @@ class _TransformableBoxState extends State { key: ValueKey(handle), handlePosition: handle, handleTapSize: widget.handleTapSize, + supportedDevices: widget.supportedResizeDevices, enabled: widget.enabledHandles.contains(handle), visible: widget.visibleHandles.contains(handle), onPanStart: (event) => onHandlePanStart(event, handle),