我想实现以下效果:当用户长按空白屏幕时,一个矩形会出现。在不松开手指的情况下,我希望用户能够拖动矩形的一条边(例如垂直方向)。
我可以分别实现这些效果(长按、释放、拖动),但我需要在不松开手指的情况下完成它们。
目前,我的代码如下:
@override
Widget build(BuildContext context) {
return GestureDetector(
onPanStart: startDrag,
onPanUpdate: onDrag,
onPanEnd: endDrag,
child: CustomPaint(
painter: BoxPainter(
color: BOX_COLOR,
boxPosition: boxPosition,
boxPositionOnStart: boxPositionOnStart ?? boxPosition,
touchPoint: point,
),
child: Container(),
),
);
}
这实现了边缘拖动,基于这个教程。
为了使元素在长时间按压时出现,我使用了一个Opacity
小部件。
@override
Widget build(BuildContext context) {
return new GestureDetector(
onLongPress: () {
setState(() {
this.opacity = 1.0;
});
},
child: new Container(
width: width,
height: height,
child: new Opacity(
opacity: opacity,
child: PhysicsBox(
boxPosition: 0.5,
),
),
),
);
}
endDrag(DragEndDetails d) { print('结束 $d'); }
- Matt Takao