我有一个关于移动应用开发的小问题希望你能帮我解答。也就是说,当您按住 Messenger 上的某个对话时,其后面的屏幕会变暗,并显示一个突出的窗口,下面有一个工具栏,其中包含删除或存档等选项。这类似于在消息中添加反应。我想知道这个事件叫什么以及如何用 flutter 语言来完成它。我希望有人能为我回答这个问题。谢谢大家!
我尝试了很多次搜索但没有成功
如何实现它的示例
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Long Press Example'),
),
body: Center(
child: GestureDetector(
onLongPress: () {
_showPopupMenu(context);
},
child: Container(
width: 200,
height: 200,
color: Colors.blue,
child: Center(
child: Text(
'Long Press Me',
style: TextStyle(color: Colors.white),
),
),
),
),
),
);
}
void _showPopupMenu(BuildContext context) {
final RenderBox overlay = Overlay.of(context).context.findRenderObject();
final RenderBox box = context.findRenderObject();
final RelativeRect position = RelativeRect.fromRect(
Rect.fromPoints(
box.localToGlobal(Offset.zero, ancestor: overlay),
box.localToGlobal(box.size.bottomRight(Offset.zero), ancestor: overlay),
),
Offset.zero & overlay.size,
);
showMenu(
context: context,
position: position,
items: <PopupMenuEntry>[
PopupMenuItem(
child: Text('Option 1'),
value: 'option1',
),
PopupMenuItem(
child: Text('Option 2'),
value: 'option2',
),
],
);
}
}