使用 Flutter Android 和 iOS 模块,您可以使用 AppLifeCycleState 来检测应用程序何时进入后台。
Flutter Web 是否有类似的东西,我可以检测到浏览器/标签的关闭或刷新?
如果此人关闭浏览器或刷新,我基本上想运行 Firestore 命令。
最佳答案
您可以使用“onBeforeUnload”功能来检查选项卡是否正在关闭。它也可能检测到页面刷新。
import 'dart:html' as html;
html.window.onBeforeUnload.listen((event) async{
// do something
});
或者import 'dart:html' as html;
html.window.onUnload.listen((event) async{
// do something
});
关于 flutter 网页 : Detect browser/tab close or refresh?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62237262/