我正在尝试实现诸如 whatsapp 语音笔记删除之类的关闭小部件功能。 当麦克风按钮处于长按状态时,我无法激活图标上的关闭。我想在拖动时推动容器。
GestureDetector(
onLongPressEnd: (LongPressEndDetails d) {
setState(() {
_showAudioControls = false;
_micSize = 24.0;
_startRecording = false;
});
},
onLongPress: () {
setState(() {
_showAudioControls = true;
_micSize = _micMaxSize;
_startRecording = true;
});
},
child: AnimatedSize(
vsync: this,
duration: Duration(milliseconds: 150),
curve: Curves.fastOutSlowIn,
child: Container(
width: _micSize == 44 ? 60 : 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.black,
),
),
child: Icon(
Icons.mic,
size: _micSize, //34
),
),
),
)
答案 0 :(得分:1)
你可以试试这个
GestureDetector(
// ...
onLongPressStart: (_) {
// start recording
},
onLongPressEnd: (_) {
// stop recording
},
onLongPressMoveUpdate: (details) {
Offset localPosition = details.localPosition;
// update your container position with offset
},
),