Skip to content

Commit f03e813

Browse files
committed
Rotation #7
1 parent 11bde37 commit f03e813

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

packages/flutter_box_transform/lib/src/transformable_box.dart

+32-13
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,14 @@ class TransformableBox extends StatefulWidget {
371371

372372
enum _PrimaryGestureOperation {
373373
resize,
374-
drag;
374+
drag,
375+
rotate;
375376

376377
bool get isDragging => this == _PrimaryGestureOperation.drag;
377378

378379
bool get isResizing => this == _PrimaryGestureOperation.resize;
380+
381+
bool get isRotating => this == _PrimaryGestureOperation.rotate;
379382
}
380383

381384
class _TransformableBoxState extends State<TransformableBox> {
@@ -389,7 +392,9 @@ class _TransformableBoxState extends State<TransformableBox> {
389392

390393
bool get isResizing => primaryGestureOperation?.isResizing == true;
391394

392-
bool get isGestureActive => isDragging || isResizing;
395+
bool get isRotating => primaryGestureOperation?.isRotating == true;
396+
397+
bool get isGestureActive => isDragging || isResizing || isRotating;
393398

394399
bool mismatchedHandle(HandlePosition handle) =>
395400
lastHandle != null && lastHandle != handle;
@@ -602,28 +607,35 @@ class _TransformableBoxState extends State<TransformableBox> {
602607
};
603608

604609
void onHandleRotateStart(DragStartDetails event, HandlePosition handle) {
610+
if (isGestureActive) return;
611+
612+
primaryGestureOperation = _PrimaryGestureOperation.rotate;
613+
lastHandle = handle;
614+
605615
final offset =
606616
widget.handleAlignment.offset(widget.rotationHandleGestureSize);
607617
initialPos = rectQuadrantOffset(handle.quadrant) +
608618
event.localPosition -
609619
Offset(offset, offset);
610620
localPos = initialPos;
611621
setState(() {});
622+
612623
// Two fingers were used to start the drag. This produces issues with
613624
// the box drag event. Therefore, we ignore it.
614-
if (event.kind == PointerDeviceKind.trackpad) {
615-
isLegalGesture = false;
616-
return;
617-
} else {
618-
isLegalGesture = true;
619-
}
625+
// if (event.kind == PointerDeviceKind.trackpad) {
626+
// isLegalGesture = false;
627+
// return;
628+
// } else {
629+
// isLegalGesture = true;
630+
// }
620631

621632
controller.onRotateStart(initialPos);
622633
widget.onRotationStart?.call(handle, event);
623634
}
624635

625636
void onHandleRotateUpdate(DragUpdateDetails event, HandlePosition handle) {
626-
if (!isLegalGesture) return;
637+
if (!isGestureActive) return;
638+
627639
final offset =
628640
widget.handleAlignment.offset(widget.rotationHandleGestureSize);
629641
localPos = rectQuadrantOffset(handle.quadrant) +
@@ -659,7 +671,10 @@ class _TransformableBoxState extends State<TransformableBox> {
659671
}
660672

661673
void onHandleRotateEnd(DragEndDetails event, HandlePosition handle) {
662-
if (!isLegalGesture) return;
674+
if (!isGestureActive) return;
675+
676+
primaryGestureOperation = null;
677+
lastHandle = null;
663678

664679
controller.onRotateEnd();
665680
widget.onRotationEnd?.call(handle, event);
@@ -673,7 +688,10 @@ class _TransformableBoxState extends State<TransformableBox> {
673688
}
674689

675690
void onHandleRotateCancel(HandlePosition handle) {
676-
if (!isLegalGesture) return;
691+
if (!isGestureActive) return;
692+
693+
primaryGestureOperation = null;
694+
lastHandle = null;
677695

678696
controller.onRotateEnd();
679697
widget.onRotationCancel?.call(handle);
@@ -832,7 +850,8 @@ class _TransformableBoxState extends State<TransformableBox> {
832850
resizeHandleGestureSize: widget.resizeHandleGestureSize,
833851
rotationHandleGestureSize:
834852
widget.rotationHandleGestureSize,
835-
supportedDevices: widget.supportedResizeDevices,enabled: widget.enabledHandles.contains(handle),
853+
supportedDevices: widget.supportedResizeDevices,
854+
enabled: widget.enabledHandles.contains(handle),
836855
visible: widget.visibleHandles.contains(handle),
837856
rotatable: widget.rotatable,
838857
// Resize
@@ -862,7 +881,7 @@ class _TransformableBoxState extends State<TransformableBox> {
862881
rotationHandleGestureSize:
863882
widget.rotationHandleGestureSize,
864883
rotatable: widget.rotatable,
865-
supportedDevices: widget.supportedResizeDevices,
884+
supportedDevices: widget.supportedResizeDevices,
866885
enabled: widget.enabledHandles.contains(handle),
867886
visible: widget.visibleHandles.contains(handle),
868887
onPanStart: (event) => onHandlePanStart(event, handle),

0 commit comments

Comments
 (0)