我试图检测应用程序关闭时颤动。飞镖有什么办法吗?
我尝试使用WidgetsBindingObserver但 flutter 只能检测 AppLifecycleState 的paused、inactive(我相信在 IOS 上)、resumed和detached。
class ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver{
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
setState(() {
_notification = state;
});
switch (state) {
case AppLifecycleState.paused:
print('paused');
break;
case AppLifecycleState.inactive:
print('inactive');
break;
case AppLifecycleState.resumed:
print('resumed');
break;
case AppLifecycleState.detached:
print('detached');
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试关闭我的应用程序,它的打印仅暂停。
我想要做的是当应用程序在聊天屏幕上关闭时。我想在我的firestore上写点东西。但我找不到办法做到这一点。
编辑:我所说的关闭是指我自己故意关闭应用程序。(按主页键并向上滑动)
这是应用程序关闭时的终端日志
D/EGL_emulation( 9248): eglMakeCurrent: 0xdb81aba0: ver 3 0 (tinfo 0xdb80fa70)
I/flutter ( 9248): state = …Run Code Online (Sandbox Code Playgroud) 正如我上面提到的,我在 Nuxt.js 上的 Axios 没有正确捕获错误
我需要知道错误,所以我可以提示让用户知道他们的输入不正确但它只是console.log错误代码状态而不是来自我的 API 的消息
这是我的代码
await axios
.post(
"API LINK",
{
email: user.email,
password: "123456",
name: user.name,
dob: user.dob ?? null,
gender: user.gender ?? null,
profileImage: imageUrl ?? user.profileImage,
userType: user.userType
}
)
.then(res => {
console.log("success");
console.log(res);
})
.catch(err => {
console.log('fail');
console.log(err)
})
Run Code Online (Sandbox Code Playgroud)
这是登录 chrome 控制台的内容
error
add.vue?104b:181 Error: Request failed with status code 400
at createError (createError.js?2d83:16)
at settle (settle.js?467f:17)
at XMLHttpRequest.handleLoad (xhr.js?b50d:61)
Run Code Online (Sandbox Code Playgroud)
但是我对console.log(err) 的期望是
(This is response from …Run Code Online (Sandbox Code Playgroud)