反正有没有检测应用程序关闭颤振?

Pur*_*nut 5 lifecycle ondestroy flutter

我试图检测应用程序关闭时颤动。飞镖有什么办法吗?

我尝试使用WidgetsBindingObserver但 flutter 只能检测 AppLifecycleState 的pausedinactive(我相信在 IOS 上)、resumeddetached

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 = AppLifecycleState.paused <- after I try send app to background 
I/flutter ( 9248): state = AppLifecycleState.inactive
I/flutter ( 9248): state = AppLifecycleState.resumed
D/EGL_emulation( 9248): eglCreateContext: 0xe39acc80: maj 3 min 0 rcv 3
D/EGL_emulation( 9248): eglMakeCurrent: 0xe39acc80: ver 3 0 (tinfo 0xd840fd90)
D/EGL_emulation( 9248): eglMakeCurrent: 0xdb81aba0: ver 3 0 (tinfo 0xdb80fa70)
D/EGL_emulation( 9248): eglMakeCurrent: 0xe39acc80: ver 3 0 (tinfo 0xd840fd90)
I/flutter ( 9248): state = AppLifecycleState.inactive
D/EGL_emulation( 9248): eglMakeCurrent: 0xdb81aba0: ver 3 0 (tinfo 0xdb80fa70)
I/flutter ( 9248): state = AppLifecycleState.paused <- after I close my app
Lost connection to device.
Run Code Online (Sandbox Code Playgroud)

PS 我是 StackOverflow 的新手,并且颤抖

Agr*_*nsh 5

抱歉,没有。您只能检测到被置于后台而不是被强制关闭。