防止点击刷新按钮或提示信息(flutter web)

Prevent refresh button or prompt message if click refresh (flutter web)

我知道对于后退按钮,我们可以使用 willpopscope, 但现在我正试图阻止用户刷新页面,有没有办法禁用刷新按钮或在用户单击刷新按钮时提示消息?

willpopscope 示例

return WillPopScope (
onWillPop: () async {
  return shouldPop;
},
child: const Text('WillPopScope sample'),
);

将此添加到 lib/web/index.html 将显示一个确认对话框:

...
<body>
<script type="text/javascript">
  window.onbeforeunload = function() {
      return "Changes that you made may not be saved.";
  }
</script>
...
</body>
...

像这样: