有什么办法可以检测到应用程序在flutter上关闭?

问题描述 投票:1回答:1

我想检测应用程序在flutter上关闭。有任何方法可能在dart上吗?

我尝试使用 WidgetsBindingObserver 但flutter只能检测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;
    }
  }
}

我试着关闭我的应用程序,它只打印 停顿.

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

编辑:我说的是 封闭 就是我自己故意关闭应用。(按home键向上滑动)

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

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.我是新来的StackOverflow,和flutter

flutter lifecycle ondestroy
1个回答
0
投票

对不起,没有。你只能检测被放在后台不被强制关闭。

© www.soinside.com 2019 - 2024. All rights reserved.