【发布时间】:2018-06-12 19:09:08
【问题描述】:
我正在尝试创建以下效果:当用户在空白屏幕上长按时,会出现一个矩形。在不抬起手指的情况下,我希望用户能够拖动矩形的边缘之一(例如,垂直)。
我能够分别实现这些效果(长按、释放、拖动),但我需要在不抬起手指的情况下拥有它们。
目前,我的代码如下所示:
@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(),
),
);
}
这个实现了边缘的拖动,基于this tutorial。
为了让元素在长按时出现,我使用了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,
),
),
),
);
}
【问题讨论】:
标签: android ios dart flutter gesture