Skip to content

Commit

Permalink
Add parameters for supported devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Aug 10, 2024
1 parent 8f249d0 commit da75f1b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/flutter_box_transform/lib/src/handle_builders.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:box_transform/box_transform.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -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<PointerDeviceKind> supportedDevices;

/// Called when the handle dragging starts.
final GestureDragStartCallback? onPanStart;

Expand All @@ -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,
Expand All @@ -61,6 +67,7 @@ class CornerHandleWidget extends StatelessWidget {
if (enabled) {
child = GestureDetector(
behavior: HitTestBehavior.opaque,
supportedDevices: supportedDevices,
onPanStart: onPanStart,
onPanUpdate: onPanUpdate,
onPanEnd: onPanEnd,
Expand Down Expand Up @@ -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<PointerDeviceKind> supportedDevices;

/// Called when the handle dragging starts.
final GestureDragStartCallback? onPanStart;

Expand All @@ -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,
Expand All @@ -162,6 +173,7 @@ class SideHandleWidget extends StatelessWidget {
if (enabled) {
child = GestureDetector(
behavior: HitTestBehavior.opaque,
supportedDevices: supportedDevices,
onPanStart: onPanStart,
onPanUpdate: onPanUpdate,
onPanEnd: onPanEnd,
Expand Down
16 changes: 16 additions & 0 deletions packages/flutter_box_transform/lib/src/transformable_box.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import '../flutter_box_transform.dart';
Expand Down Expand Up @@ -66,6 +67,16 @@ class TransformableBox extends StatefulWidget {
/// visible, it will not be shown and will not be interactive.
final Set<HandlePosition> 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<PointerDeviceKind> 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<PointerDeviceKind> supportedResizeDevices;

/// The initial box that will be used to position set the initial size of
/// the [TransformableBox] widget.
///
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -576,6 +589,7 @@ class _TransformableBoxState extends State<TransformableBox> {
if (widget.draggable) {
content = GestureDetector(
behavior: HitTestBehavior.translucent,
supportedDevices: widget.supportedDragDevices,
onTap: onTap,
onPanStart: onDragPanStart,
onPanUpdate: onDragPanUpdate,
Expand Down Expand Up @@ -606,6 +620,7 @@ class _TransformableBoxState extends State<TransformableBox> {
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),
Expand All @@ -622,6 +637,7 @@ class _TransformableBoxState extends State<TransformableBox> {
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),
Expand Down

0 comments on commit da75f1b

Please sign in to comment.