Flutter web 新版本更新提示

添加这段代码到 项目/web/index.html

即可,大概是 116行

  if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
// if there's an existing controller (previous Service Worker), show the prompt
// you can tweak this and delay the notification once the page is load you can show a notification and ask for a new refresh
if (navigator.serviceWorker.controller) {
// you have a better UI here, reloading is not a great user experince here.
const confirmed = alert('New version of the app is available. Refresh now');
if (confirmed == true) {
window.location.reload();
}
}
}
});
请登录后发表评论

    没有回复内容