title: Is there anyway to detect app closed on flutter?
body: <p>I trying to detect the app close on flutter. Is there any way possible on dart?</p>
  
  <p>I try using <code>WidgetsBindingObserver</code> but flutter can only detect AppLifecycleState of <strong>paused</strong>, <strong>inactive</strong> (I believe that on IOS), <strong>resumed</strong>, and <strong>detached</strong>.</p>
  
  <pre><code>class ChatScreenState extends State&lt;ChatScreen&gt; 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;
      }
    }
  }
  </code></pre>
  
  <p>which I try closing my app its print only <strong>paused</strong>.</p>
  
  <p>What I'm trying to do is when the app closed on chatscreen. I want to write something on my firestore. But I can't find a way to do this.</p>
  
  <p>Edit: 
  what I mean by <strong>closed</strong> that is I intentionally close the app myself. (press home button and swipe up) </p>
  
  <p>this is terminal log when the app closed</p>
  
  <pre><code>D/EGL_emulation( 9248): eglMakeCurrent: 0xdb81aba0: ver 3 0 (tinfo 0xdb80fa70)
  I/flutter ( 9248): state = AppLifecycleState.paused &lt;- 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 &lt;- after I close my app
  Lost connection to device.
  </code></pre>
  
  <p>P.S. I new to StackOverflow, and flutter</p>