Flutter 颤振:有没有办法在web应用程序中获取退出事件?
我想在用户关闭或重新加载网页(web应用程序)时调用API 收听活动Flutter 颤振:有没有办法在web应用程序中获取退出事件?,flutter,flutter-web,Flutter,Flutter Web,我想在用户关闭或重新加载网页(web应用程序)时调用API 收听活动 html.window.onBeforeUnload.listen( (event) async { Map<String, dynamic> _exit = await callApi(CloseRoomAPI); print(_exit); }, ); html.window.onBeforeUnload.listen( (事件)异步{ Map _exit=wait callApi(C
html.window.onBeforeUnload.listen(
(event) async {
Map<String, dynamic> _exit = await callApi(CloseRoomAPI);
print(_exit);
},
);
html.window.onBeforeUnload.listen(
(事件)异步{
Map _exit=wait callApi(CloseRoomAPI);
打印(_退出);
},
);
调用API函数
Future<Map<String, dynamic>> callApi(String _url) async {
final client = new http.Client();
final connection = await client.get(_url);
if (connection.statusCode == 200) {
return jsonDecode(connection.body.toString());
} else {
return null;
}
}
Future callApi(String\u url)异步{
final client=new http.client();
最终连接=等待client.get(_url);
如果(connection.statusCode==200){
返回jsonDecode(connection.body.toString());
}否则{
返回null;
}
}
-YMMV。可能会用这个词来找到特定于颤振的东西YMMV。可能会使用该术语来查找特定于颤振的内容。