support use command and shift to fix the height or width
This commit is contained in:
1 parent
c95c0e192e
commit
cb4531f046
1 file changed
+53
-1
+53
-1
@@ -27,6 +27,19 @@ class _DraggableAreaState extends State<DraggableArea> {
|
|||||||
double? end;
|
double? end;
|
||||||
FocusNode node = FocusNode();
|
FocusNode node = FocusNode();
|
||||||
|
|
||||||
|
bool isPressCommand = false;
|
||||||
|
bool isPressShift = false;
|
||||||
|
|
||||||
|
Axis? get axis {
|
||||||
|
if (isPressCommand) {
|
||||||
|
return Axis.vertical;
|
||||||
|
}
|
||||||
|
if (isPressShift) {
|
||||||
|
return Axis.horizontal;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Focus(
|
return Focus(
|
||||||
@@ -39,10 +52,15 @@ class _DraggableAreaState extends State<DraggableArea> {
|
|||||||
left: left,
|
left: left,
|
||||||
top: top,
|
top: top,
|
||||||
child: Draggable(
|
child: Draggable(
|
||||||
|
axis: axis,
|
||||||
feedback: widget.child,
|
feedback: widget.child,
|
||||||
childWhenDragging: const SizedBox.shrink(),
|
childWhenDragging: const SizedBox.shrink(),
|
||||||
onDragUpdate: (u) => onUpdate(u),
|
onDragUpdate: (u) => onUpdate(u),
|
||||||
onDragEnd: (detail) => onEnd(detail.offset),
|
onDragEnd: (detail) => onEnd(detail.offset),
|
||||||
|
onDragStarted: () {
|
||||||
|
first = null;
|
||||||
|
end = null;
|
||||||
|
},
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -62,12 +80,31 @@ class _DraggableAreaState extends State<DraggableArea> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onUpdate(DragUpdateDetails u) {
|
onUpdate(DragUpdateDetails u) {
|
||||||
|
if (isPressShift) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
first ??= u.globalPosition.dy;
|
first ??= u.globalPosition.dy;
|
||||||
end = u.globalPosition.dy;
|
end = u.globalPosition.dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyEventResult onKeyInput(FocusNode nodef, KeyEvent value) {
|
KeyEventResult onKeyInput(FocusNode nodef, KeyEvent value) {
|
||||||
if (value is! KeyDownEvent && value is! KeyRepeatEvent) {
|
if (value is KeyDownEvent && isCommand(value)) {
|
||||||
|
isPressCommand = true;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
if (value is KeyUpEvent && isCommand(value)) {
|
||||||
|
isPressCommand = false;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
if (value is KeyDownEvent && isShift(value)) {
|
||||||
|
isPressShift = true;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
if (value is KeyUpEvent && isShift(value)) {
|
||||||
|
isPressShift = false;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
if (value is! KeyDownEvent && value is! KeyRepeatEvent) {
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
}
|
}
|
||||||
var x = 0;
|
var x = 0;
|
||||||
@@ -90,3 +127,18 @@ class _DraggableAreaState extends State<DraggableArea> {
|
|||||||
return KeyEventResult.handled;
|
return KeyEventResult.handled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isShift(KeyEvent e) {
|
||||||
|
var key = e.logicalKey;
|
||||||
|
return key == LogicalKeyboardKey.shiftLeft || key == LogicalKeyboardKey.shiftRight || key == LogicalKeyboardKey.shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isCommand(KeyEvent e) {
|
||||||
|
var key = e.logicalKey;
|
||||||
|
return key == LogicalKeyboardKey.metaLeft ||
|
||||||
|
key == LogicalKeyboardKey.metaRight ||
|
||||||
|
key == LogicalKeyboardKey.meta ||
|
||||||
|
key == LogicalKeyboardKey.controlLeft ||
|
||||||
|
key == LogicalKeyboardKey.controlRight ||
|
||||||
|
key == LogicalKeyboardKey.control;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user