我正在尝试创建以下效果:当用户长按空白屏幕时,会出现一个矩形。在不抬起手指的情况下,我希望用户能够拖动矩形的边缘之一(例如,垂直)。
我可以分别实现这些效果(长按、释放、拖动),但我需要在不抬起手指的情况下获得它们。
目前,我的代码如下所示:
@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(),
),
);
}
Run Code Online (Sandbox Code Playgroud)
这实现了边缘的拖动,以本教程为基础。
为了让元素出现在长按中,我使用了一个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,
),
),
),
); …Run Code Online (Sandbox Code Playgroud)