反正有没有检测应用程序在颤动时关闭?

Is there anyway to detect app closed on flutter?

我正在尝试检测应用程序在 flutter 时关闭。 dart 有什么办法吗?

我尝试使用 WidgetsBindingObserver 但 flutter 只能检测 pausedinactive 的 AppLifecycleState(我相信 IOS)、恢复分离

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;
    }
  }
}

我尝试关闭我的应用程序,它只打印 paused

我想做的是当应用程序在聊天屏幕上关闭时。我想在我的 Firestore 上写点东西。但是我找不到办法做到这一点。

编辑: 我所说的 closed 是我自己故意关闭应用程序的意思。 (按下主页按钮并向上滑动)

这是应用关闭时的终端日志

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.

P.S。我是 Whosebug 的新手,并且 flutter

抱歉,没有。只能检测到后台没有强制关闭